From a4668ea43723a413facbb6dc59e9bb8576a66bfe Mon Sep 17 00:00:00 2001 From: SouthBennett <146032836+SouthBennett@users.noreply.github.com> Date: Tue, 7 Apr 2026 22:09:03 -0700 Subject: [PATCH 01/11] implemented oddSum. All tests are successful --- src/Practice.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index ca8e22b..b6dbd6a 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -12,7 +12,21 @@ 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 oddSum = 0; + + for (int num : nums) { + if (num % 2 != 0) { + oddSum += num; + } + } + + if (oddSum == 0) { + return 0; + } + + return oddSum; } /** From 6e2eaa4313aa7be0bf48e08532258e460df46bd3 Mon Sep 17 00:00:00 2001 From: SouthBennett <146032836+SouthBennett@users.noreply.github.com> Date: Wed, 8 Apr 2026 12:39:35 -0700 Subject: [PATCH 02/11] implemented shortestWord. All tests pass --- src/Practice.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index b6dbd6a..5a5d089 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -41,7 +41,23 @@ 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("Set is null"); + + if (words.isEmpty()) throw new IllegalArgumentException("Set is empty"); + + String shortestWord = ""; + + for (String word : words) { + if (shortestWord.equals("") || word.length() < shortestWord.length()) { + shortestWord = word; + + } else if (word.length() == shortestWord.length() && word.compareTo(shortestWord) < 0) { + shortestWord = word; + } + } + + return shortestWord; } /** From 2adbcf2ae4a5e269e7e0b5eb12fbd441820a6ec4 Mon Sep 17 00:00:00 2001 From: SouthBennett <146032836+SouthBennett@users.noreply.github.com> Date: Wed, 8 Apr 2026 12:51:20 -0700 Subject: [PATCH 03/11] implemented adults method. All tests pass --- src/Practice.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 5a5d089..7f3a63d 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; @@ -70,7 +71,17 @@ 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("Ages is null"); + + Set names = new HashSet<>(); + + for (String name : ages.keySet()) { + int age = ages.get(name); + if (age >= 18) { + names.add(name); + } + } + return names; } /** From c1cb748b35da20b88c05eaeb8f548f00487437ea Mon Sep 17 00:00:00 2001 From: SouthBennett <146032836+SouthBennett@users.noreply.github.com> Date: Wed, 8 Apr 2026 13:05:05 -0700 Subject: [PATCH 04/11] Implemented biggestNumber method. All tests pass --- src/Practice.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 7f3a63d..54d8a5f 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -92,7 +92,19 @@ 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("Head is null"); + + ListNode current = head; + + int biggest = Integer.MIN_VALUE; + + while (current != null) { + if (current.data > biggest) { + biggest = current.data; + } + current = current.next; + } + return biggest; } /** From 59451cf77a41cf2568be2caa4b7f981d7bc5c9dc Mon Sep 17 00:00:00 2001 From: SouthBennett <146032836+SouthBennett@users.noreply.github.com> Date: Wed, 8 Apr 2026 13:53:09 -0700 Subject: [PATCH 05/11] Implemented frequencies method. All tests pass --- src/Practice.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 54d8a5f..dbb0e59 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; @@ -121,7 +122,20 @@ public static int biggestNumber(ListNode head) { * @return a frequency map of values in the list */ public static Map frequencies(ListNode head) { - return null; + Map freqMap = new HashMap<>(); + + ListNode current = head; + + while (current != null) { + if (!freqMap.containsKey(current.data)) { + freqMap.put(current.data, 1); + } else { + int count = freqMap.get(current.data) + 1; + freqMap.put(current.data, count); + } + current = current.next; + } + return freqMap; } From 095f96ee5f6ff318a9134362dc74c3a8606bef77 Mon Sep 17 00:00:00 2001 From: SouthBennett <146032836+SouthBennett@users.noreply.github.com> Date: Wed, 8 Apr 2026 14:21:04 -0700 Subject: [PATCH 06/11] implemented levelCount. All tests pass --- src/Practice.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index dbb0e59..b87680f 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -148,7 +148,17 @@ 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 leftLevelCount = levelCount(root.left); + + int rightLevelCount = levelCount(root.right); + + if (leftLevelCount > rightLevelCount) { + return 1 + leftLevelCount; + } else { + return 1 + rightLevelCount; + } } From 210d63bf09fc21ac5932762e709b1d4ac970a71c Mon Sep 17 00:00:00 2001 From: SouthBennett <146032836+SouthBennett@users.noreply.github.com> Date: Wed, 8 Apr 2026 14:36:15 -0700 Subject: [PATCH 07/11] implemented sumAtLevel. All tests pass --- src/Practice.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index b87680f..bafa12a 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -186,7 +186,15 @@ 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) return 0; + + if (level == 1) return root.data; + + int leftLevelSum = sumAtLevel(root.left, level - 1); + + int rightLevelSum = sumAtLevel(root.right, level - 1); + + return rightLevelSum + leftLevelSum; } From 25e1a60c0f6d1c10b7824640465bc2c33bac051a Mon Sep 17 00:00:00 2001 From: SouthBennett <146032836+SouthBennett@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:05:10 -0700 Subject: [PATCH 08/11] implemented sumMatch. All tests pass --- src/Practice.java | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index bafa12a..ea2afc3 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -209,7 +209,30 @@ 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; + int treeSum = sumTree(root); + int listSum = sumList(head); + + return treeSum == listSum; + } + + private static int sumTree(BinaryTreeNode root) { + if (root == null) return 0; + + return root.data + sumTree(root.left) + sumTree(root.right); + } + + private static int sumList(ListNode head) { + if (head == null) return 0; + + int sum = 0; + + ListNode current = head; + + while (current != null) { + sum += current.data; + current = current.next; + } + return sum; } /** From a436d6ea488858a8fae5d0420a34bab20b9595fb Mon Sep 17 00:00:00 2001 From: SouthBennett <146032836+SouthBennett@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:23:24 -0700 Subject: [PATCH 09/11] implemented nbSum method. All tests are successful --- src/Practice.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index ea2afc3..59f8703 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -244,7 +244,14 @@ private static int sumList(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 b5f7b99c9bceb36087c69b4549c847149e0da1e1 Mon Sep 17 00:00:00 2001 From: SouthBennett <146032836+SouthBennett@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:56:57 -0700 Subject: [PATCH 10/11] implemented onlyChildCount. Tests pass --- src/Practice.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 59f8703..3450db6 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -283,7 +283,15 @@ 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 cdf4737448507b0ba20c27b40a1d7910acd1e846 Mon Sep 17 00:00:00 2001 From: SouthBennett <146032836+SouthBennett@users.noreply.github.com> Date: Wed, 8 Apr 2026 16:29:47 -0700 Subject: [PATCH 11/11] implemented maxDepth. All tests pass --- src/Practice.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index 3450db6..fba2856 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -328,7 +328,24 @@ public static int onlyChildCount(TreeNode root) { * @param root the root value of the tree * @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; + public static int maxDepth(Map> tree, T root) { + if (tree == null || root == null || !tree.containsKey(root)) return 0; + return maxDepthHelper(tree, root); + } + + private static int maxDepthHelper(Map> tree, T node) { + List children = tree.get(node); + + if (children == null || children.isEmpty()) { + return 1; + } + + int deepest = 0; + + for (T child : children) { + int childDepth = maxDepthHelper(tree, child); + deepest = Math.max(deepest, childDepth); + } + return 1 + deepest; } } \ No newline at end of file