From 28e912fccca6b3292ec7a6b0c7cd77f6da562ef8 Mon Sep 17 00:00:00 2001 From: samkosal <67755908+samkosal@users.noreply.github.com> Date: Wed, 8 Apr 2026 00:49:28 -0700 Subject: [PATCH 1/3] finished half of the problem --- src/Practice.java | 75 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index ca8e22b..6273969 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -1,6 +1,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.HashSet; +import java.util.HashMap; public class Practice { /** @@ -12,7 +14,17 @@ 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 == 1 || num % 2 == -1) { + sum += num; + } + } + return sum; } /** @@ -27,7 +39,20 @@ public static int oddSum(int[] nums) { * @throws NullPointerException if words is null */ public static String shortestWord(Set words) { - return null; + if (words.isEmpty()) { + throw new IllegalArgumentException(); + } + // if (words == null) { + // throw new NullPointerException(); + // } + String shortest = "adsfadsfadsfasdfadsfadsf"; + for (String word : words) { + if (word.length() < shortest.length() || (word.length() == shortest.length() && word.compareTo(shortest) < 0) ) { + shortest = word; + } + } + + return shortest; } /** @@ -40,7 +65,21 @@ 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 allNames = new HashSet<>(); + + for (Map.Entry entry : ages.entrySet()) { + String key = entry.getKey(); + Integer value = entry.getValue(); + + if (value >= 18) { + allNames.add(key); + } + } + + return allNames; } /** @@ -51,7 +90,22 @@ 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(); + } + + ListNode current = head; + int biggest = current.data; + + while (current.next != null) { + current = current.next; + + if (current.data > biggest) { + biggest = current.data; + } + } + + return biggest; } /** @@ -68,7 +122,18 @@ 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<>(); + if (head == null) { + return freqMap; + } + + ListNode current = head; + while (current != null) { + freqMap.put(current.data, freqMap.getOrDefault(current.data, 0) + 1); + current = current.next; + } + + return freqMap; } From 8229671e177852e45971afd80501bd8591625cf9 Mon Sep 17 00:00:00 2001 From: samkosal <67755908+samkosal@users.noreply.github.com> Date: Thu, 9 Apr 2026 00:48:53 -0700 Subject: [PATCH 2/3] finished frequencies --- src/Practice.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 6273969..80def9a 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -146,7 +146,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 left + right + 1; } From 31aa921f0885016c7ed1150ee6021807ff526731 Mon Sep 17 00:00:00 2001 From: samkosal <67755908+samkosal@users.noreply.github.com> Date: Thu, 9 Apr 2026 00:50:42 -0700 Subject: [PATCH 3/3] finished levelcount --- src/Practice.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 80def9a..ee5bcf9 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -153,7 +153,7 @@ public static int levelCount(BinaryTreeNode root) { int left = levelCount(root.left); int right = levelCount(root.right); - return left + right + 1; + return Math.max(left, right) + 1; }