From 8cf21347543a25ad6275ae6f4ccfab7151b9760a Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 8 Apr 2026 22:45:44 -0700 Subject: [PATCH 01/11] finished oddSum --- src/Practice.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index ca8e22b..52224a5 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -12,7 +12,15 @@ public class Practice { * @return the sum of the odd numbers in the array */ public static int oddSum(int[] nums) { - return 0; + if(nums == null)return 0; + int sum = 0; + for(int i = 0; i < nums.length;i++){ + if(nums[i] % 2 != 0){ + sum += nums[i]; + } + } + + return sum; } /** From 99e6f974854218065d26b789f08d10720c0fa405 Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 8 Apr 2026 22:57:51 -0700 Subject: [PATCH 02/11] finished shortestWord --- src/Practice.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 52224a5..3384547 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -35,7 +35,22 @@ public static int oddSum(int[] nums) { * @throws NullPointerException if words is null */ public static String shortestWord(Set words) { - return null; + if(words == null) throw new NullPointerException(); + if(words.isEmpty()) throw new IllegalArgumentException(); + + String shortest = ""; + int smallest = Integer.MAX_VALUE; + + for (String word : words) { + if(word.length() < smallest){ + shortest = word; + smallest = word.length(); + } else if( word.length() == smallest && word.compareTo(shortest) < 0){ + shortest = word; + } + } + + return shortest; } /** From dac5428a962f7e79ece955b645e89b2efac9d25f Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 8 Apr 2026 23:14:58 -0700 Subject: [PATCH 03/11] finished adults --- src/Practice.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 3384547..89521dc 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -1,3 +1,4 @@ +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -63,7 +64,20 @@ public static String shortestWord(Set words) { * @throws NullPointerException if ages is null */ public static Set adults(Map ages) { - return null; + if(ages == null) throw new NullPointerException(); + + Set names = new HashSet<>(); + + for(Map.Entry map : ages.entrySet()){ + String name = map.getKey(); + Integer age = map.getValue(); + + if(age >= 18){ + names.add(name); + } + } + + return names; } /** From 2414ebd3ac37b242fcf9adda280ede3f9e05e921 Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 8 Apr 2026 23:20:26 -0700 Subject: [PATCH 04/11] finished biggestNumber --- src/Practice.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 89521dc..340ee1f 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -88,7 +88,18 @@ public static Set adults(Map ages) { * @throws IllegalArgumentException if head is null */ public static int biggestNumber(ListNode head) { - return 0; + if(head == null) throw new IllegalArgumentException(); + int biggest = Integer.MIN_VALUE; + + while(head != null){ + if(head.data > biggest){ + biggest = head.data; + } + head = head.next; + } + + + return biggest; } /** From a9b11409fc4efc41ff24a1499a4cfa863b5ee374 Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 8 Apr 2026 23:25:29 -0700 Subject: [PATCH 05/11] finished frequencies --- src/Practice.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 340ee1f..b299963 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -1,3 +1,4 @@ +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -116,7 +117,15 @@ public static int biggestNumber(ListNode head) { * @return a frequency map of values in the list */ public static Map frequencies(ListNode head) { - return null; + Map map = new HashMap<>(); + if(head == null) return map; + + while(head != null){ + map.put(head.data, map.getOrDefault(head.data, 0) + 1) ; + head = head.next; + } + + return map; } From 12640814c107a53a5320d30614dd344e596a71f9 Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 8 Apr 2026 23:30:06 -0700 Subject: [PATCH 06/11] finished level count --- src/Practice.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index b299963..8d0a5e5 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -138,7 +138,14 @@ public static Map frequencies(ListNode head) { * @return the number of levels in the tree */ public static int levelCount(BinaryTreeNode root) { - return 0; + if(root == null)return 0; + + int left = levelCount(root.left); + int right = levelCount(root.right); + + + + return Math.max(left, right) + 1; } From e58db0a608c711279a892d1c96356e7b5c93d196 Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 8 Apr 2026 23:36:14 -0700 Subject: [PATCH 07/11] finished sumAtLevel --- src/Practice.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 8d0a5e5..66a5f90 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -173,7 +173,10 @@ public static int levelCount(BinaryTreeNode root) { * @return the sum of the nodes at the given level */ public static int sumAtLevel(BinaryTreeNode root, int level) { - return 0; + if (root == null || level < 1) return 0; + if (level == 1) return root.data; + + return sumAtLevel(root.left, level - 1) + sumAtLevel(root.right, level - 1); } From d18cc0822ab0d6f63d528e9c231c844c21ca091b Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 8 Apr 2026 23:41:58 -0700 Subject: [PATCH 08/11] fisnished sumMatch --- src/Practice.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 66a5f90..b6c4779 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -191,7 +191,21 @@ public static int sumAtLevel(BinaryTreeNode root, int level) { * @return true if the sums are equal, false otherwise */ public static boolean sumMatch(BinaryTreeNode root, ListNode head) { - return false; + return treeSum(root) == listSum(head); + } + + private static int treeSum(BinaryTreeNode root) { + if (root == null) return 0; + return root.data + treeSum(root.left) + treeSum(root.right); + } + + private static int listSum(ListNode head) { + int sum = 0; + while (head != null) { + sum += head.data; + head = head.next; + } + return sum; } /** From fe212737a43111f6c9f31db8dc29de7b5669c0dc Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 8 Apr 2026 23:47:40 -0700 Subject: [PATCH 09/11] finished nbSum --- src/Practice.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index b6c4779..ec03674 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -217,7 +217,15 @@ private static int listSum(ListNode head) { * @return the sum of all the tree's values */ public static int nbSum(TreeNode root) { - return 0; + if (root == null) return 0; + + int sum = root.data; + + for (TreeNode child : root.children) { + sum += nbSum(child); + } + + return sum; } /** From 4ce97e91f065e850dd445e7d6c994b35dd1304c6 Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 8 Apr 2026 23:52:36 -0700 Subject: [PATCH 10/11] finished onlyChildCount --- src/Practice.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index ec03674..f226342 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -257,7 +257,16 @@ public static int nbSum(TreeNode root) { * @return the count of nodes that do not have siblings, EXCLUDING THE ROOT */ public static int onlyChildCount(TreeNode root) { - return 0; + if (root == null) return 0; + int count = 0; + for (TreeNode child : root.children) { + if (root.children.size() == 1) { + count++; + } + count += onlyChildCount(child); + } + + return count; } /** From 54a2356320e580f865fa074086786d2239e80c59 Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 8 Apr 2026 23:58:01 -0700 Subject: [PATCH 11/11] finished maxDepth --- src/Practice.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index f226342..160b3f9 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -1,3 +1,4 @@ +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -304,6 +305,19 @@ public static int onlyChildCount(TreeNode root) { * @return the depth of the tree, or 0 if the tree is null or the root is not present in the tree */ public static int maxDepth(Map> tree, T root) { - return 0; - } + if (tree == null || root == null || !tree.containsKey(root)) return 0; + return maxDepthHelper(tree, root); + }; + + private static int maxDepthHelper(Map> tree, T root) { + if (!tree.containsKey(root)) return 1; + + int max = 0; + + for (T child : tree.get(root)) { + max = Math.max(max, maxDepthHelper(tree, child)); + } + + return max + 1; + } } \ No newline at end of file