From 4bfe5d52bb433c4d7e77895e18baa1fb2255a340 Mon Sep 17 00:00:00 2001 From: jmakho01 <210610870+jmakho01@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:04:35 -0700 Subject: [PATCH 01/10] Implemented oddSum() method --- src/Practice.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index ca8e22b..1da36b1 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -12,7 +12,12 @@ 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 num : nums) { + if(num % 2 != 0) { sum += num; } + } + return sum; } /** From 34958c98aaa2288bbd58c0d27c23abbda926e33d Mon Sep 17 00:00:00 2001 From: jmakho01 <210610870+jmakho01@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:22:28 -0700 Subject: [PATCH 02/10] Implemented shortestWord() method --- src/Practice.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 1da36b1..d9a4802 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -32,7 +32,21 @@ 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(); + int wordLength = 99; + String shortest = ""; + for(String word : words) { + if(word.length() < wordLength) { + wordLength = word.length(); + shortest = word; + } else if(word.length() == wordLength) { + if(word.compareTo(shortest) < 0) { + shortest = word; + } + } + } + return shortest; } /** From 279180c9565f573618bb18c44d04bdc800ee2abe Mon Sep 17 00:00:00 2001 From: jmakho01 <210610870+jmakho01@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:42:07 -0700 Subject: [PATCH 03/10] Implemented adults() method --- src/Practice.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index d9a4802..af14d2c 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -1,4 +1,5 @@ import java.util.List; +import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -59,7 +60,12 @@ 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 eighteen = new HashSet<>(); + for(String name : ages.keySet()) { + if(ages.get(name) >= 18) { eighteen.add(name); } + } + return eighteen; } /** From 8109fad4c14f45d10e8db74d8730ad6e23aff0e8 Mon Sep 17 00:00:00 2001 From: jmakho01 <210610870+jmakho01@users.noreply.github.com> Date: Wed, 8 Apr 2026 16:10:52 -0700 Subject: [PATCH 04/10] Implemented biggestNumber() method --- src/Practice.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index af14d2c..94b47fc 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -76,7 +76,14 @@ 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 = -99; + ListNode current = head; + while(current != null) { + if(current.data > biggest) { biggest = current.data; } + current = current.next; + } + return biggest; } /** From d766bc34a66bf8ebe3d72a6dfc8ec64ef06f4cc7 Mon Sep 17 00:00:00 2001 From: jmakho01 <210610870+jmakho01@users.noreply.github.com> Date: Wed, 8 Apr 2026 16:20:00 -0700 Subject: [PATCH 05/10] Implemented frequencies() method --- src/Practice.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 94b47fc..d258cfe 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -1,6 +1,7 @@ import java.util.List; import java.util.HashSet; import java.util.Map; +import java.util.HashMap; import java.util.Set; public class Practice { @@ -100,7 +101,19 @@ public static int biggestNumber(ListNode head) { * @return a frequency map of values in the list */ public static Map frequencies(ListNode head) { - return null; + Map frequency = new HashMap<>(); + ListNode current = head; + while(current != null) { + if(frequency.containsKey(current.data) == false) { + frequency.put(current.data, 1); + } + else { + int temp = frequency.get(current.data); + frequency.put(current.data, temp + 1); + } + current = current.next; + } + return frequency; } From 73c9c80164b9a7e6d7dca5e84e38a6705101377e Mon Sep 17 00:00:00 2001 From: jmakho01 <210610870+jmakho01@users.noreply.github.com> Date: Wed, 8 Apr 2026 16:23:03 -0700 Subject: [PATCH 06/10] Implemented levelCount() method --- src/Practice.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index d258cfe..aa2f8d9 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -126,7 +126,8 @@ 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; + return 1 + Math.max(levelCount(root.left), levelCount(root.right)); } From c740da4f4bb82722a2b01f93c958222ad18cf8c4 Mon Sep 17 00:00:00 2001 From: jmakho01 <210610870+jmakho01@users.noreply.github.com> Date: Wed, 8 Apr 2026 16:38:09 -0700 Subject: [PATCH 07/10] Implemented sumAtLevel() method --- src/Practice.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index aa2f8d9..111b4ce 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -155,7 +155,9 @@ 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 bad9d97e28912a1ca8795a08690843bc0b5d8605 Mon Sep 17 00:00:00 2001 From: jmakho01 <210610870+jmakho01@users.noreply.github.com> Date: Wed, 8 Apr 2026 16:45:42 -0700 Subject: [PATCH 08/10] Implemented sumTree() method --- src/Practice.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 111b4ce..fee85c5 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -172,7 +172,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; + int binarySum = sumTree(root); + int listSum = 0; + if(head != null) { + ListNode current = head; + while(current != null) { + listSum += current.data; + current = current.next; + } + } + return listSum == binarySum; + } + + private static int sumTree(BinaryTreeNode root) { + if(root == null) return 0; + return root.data + sumTree(root.left) + sumTree(root.right); } /** From 5605284a9a2615f868b19d18ac8e447c1e5bf9e4 Mon Sep 17 00:00:00 2001 From: jmakho01 <210610870+jmakho01@users.noreply.github.com> Date: Wed, 8 Apr 2026 16:58:50 -0700 Subject: [PATCH 09/10] Implemented onlyChildCount() method --- src/Practice.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index fee85c5..84465a7 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -198,7 +198,10 @@ private static int sumTree(BinaryTreeNode root) { * @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; } /** @@ -230,7 +233,11 @@ 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) { count += onlyChildCount(child); } + if(root.children.size() == 1) { count++; } + return count; } /** From e4087042c91d5aa2b695e911ab89ba2a83b2b12e Mon Sep 17 00:00:00 2001 From: jmakho01 <210610870+jmakho01@users.noreply.github.com> Date: Wed, 8 Apr 2026 17:29:42 -0700 Subject: [PATCH 10/10] Implemented maxDepth() method --- src/Practice.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 84465a7..67450e5 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -275,6 +275,16 @@ 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; } + int treeDepth = 0; + List children = tree.get(root); + if(children == null || children.isEmpty()) { return 1; } + for(T child : children) { + int childDepth = 0; + if(tree.containsKey(child)) { childDepth = maxDepth(tree, child); } + else { childDepth = 1; } + if(childDepth > treeDepth) { treeDepth = childDepth; } + } + return treeDepth + 1; } } \ No newline at end of file