From 032a2090ba318d5a25e2c2efb811289bec275292 Mon Sep 17 00:00:00 2001 From: Ebtisam Jelani <93232997+Ebtisam0402@users.noreply.github.com> Date: Wed, 8 Apr 2026 09:45:16 -0700 Subject: [PATCH 1/9] sum all odd numbers is completed --- src/Practice.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index ca8e22b..a288388 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -12,7 +12,16 @@ 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 4eaf62238ae025e5503d3c27e676d1877b6a05bf Mon Sep 17 00:00:00 2001 From: Ebtisam Jelani <93232997+Ebtisam0402@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:17:25 -0700 Subject: [PATCH 2/9] the shortest word in the the set is completed --- src/Practice.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index a288388..d4fe14c 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -36,7 +36,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 shortesString= null; + for(String word: words){ + if(shortesString == null ||word.length() < shortesString.length()){ + shortesString = word; + } + if(word.length() ==shortesString.length() && word.compareTo(shortesString) < 0){ + shortesString = word; + } + } + return shortesString; } /** From 901bd01712b13cb0bb3e932e221fa4f58071d4bd Mon Sep 17 00:00:00 2001 From: Ebtisam Jelani <93232997+Ebtisam0402@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:53:23 -0700 Subject: [PATCH 3/9] finding a set of all the name of peaple that are 18 and above --- src/Practice.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index d4fe14c..4045b56 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; @@ -64,7 +65,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 adultsName = new HashSet<>(); + + for (String name : ages.keySet()){ + int age = ages.get(name); + + if(age >= 18){ + adultsName.add(name); + } + } + + return adultsName; } /** From 254c2863e206cf2edcd8bd309e547712ae951242 Mon Sep 17 00:00:00 2001 From: Ebtisam Jelani <93232997+Ebtisam0402@users.noreply.github.com> Date: Wed, 8 Apr 2026 11:04:00 -0700 Subject: [PATCH 4/9] max number in the linked list --- src/Practice.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 4045b56..32a09a0 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -89,7 +89,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(); + } + int max = head.data; + ListNode current = head; + + while(current != null){ + if(current.data > max){ + max = current.data; + } + current = current.next; + } + return max; } /** From d2f1e8ffbe9aead8730caff47cd8d36fb992f81b Mon Sep 17 00:00:00 2001 From: Ebtisam Jelani <93232997+Ebtisam0402@users.noreply.github.com> Date: Wed, 8 Apr 2026 20:45:43 -0700 Subject: [PATCH 5/9] frequency map counting how frequently items apppear in the linked list --- src/Practice.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 32a09a0..3fd6b02 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; @@ -118,7 +119,21 @@ 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){ + T value = current.data; + + if(freqMap.containsKey(value)){ + freqMap.put(value, freqMap.get(value) + 1); + }else{ + freqMap.put(value, 1); + } + current = current.next; + } + return freqMap; } From e5d19c773132ca5d6879f1e69c7475e978ca29f4 Mon Sep 17 00:00:00 2001 From: Ebtisam Jelani <93232997+Ebtisam0402@users.noreply.github.com> Date: Wed, 8 Apr 2026 21:09:46 -0700 Subject: [PATCH 6/9] count the number of levels in the tree --- src/Practice.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 3fd6b02..62c4b19 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 leftNode = levelCount(root.left); + int rightNode = levelCount(root.right); + + return 1 + Math.max(leftNode, rightNode); } From 7dced28d41b1f95009cafd3c40aba4731fe67fc2 Mon Sep 17 00:00:00 2001 From: Ebtisam Jelani <93232997+Ebtisam0402@users.noreply.github.com> Date: Wed, 8 Apr 2026 23:00:53 -0700 Subject: [PATCH 7/9] the sum of all the nodes in a non-binary tree --- src/Practice.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 62c4b19..b42c179 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -208,7 +208,16 @@ public static boolean sumMatch(BinaryTreeNode root, ListNode h * @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){ + int childSum = nbSum(child); + sum+= childSum; + } + return sum; } /** From e99291cdbdd5f46f6460dbbfbee4b5ff7722e95a Mon Sep 17 00:00:00 2001 From: Ebtisam Jelani <93232997+Ebtisam0402@users.noreply.github.com> Date: Wed, 8 Apr 2026 23:13:57 -0700 Subject: [PATCH 8/9] count the nodes in the tree that do not have sibilings --- src/Practice.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Practice.java b/src/Practice.java index b42c179..5cbed68 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -249,7 +249,19 @@ 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) { + if(root == null){ return 0; + } + int count = 0; + + if(root.children != null && root.children.size() == 1){ + count += 1; + } + + for(TreeNode child: root.children){ + count += onlyChildCount(child); + } + return count; } /** From e6a22ce7c4fe0ce16bd5d2abf1c2ec92e0a7a469 Mon Sep 17 00:00:00 2001 From: Ebtisam Jelani <93232997+Ebtisam0402@users.noreply.github.com> Date: Wed, 8 Apr 2026 23:25:21 -0700 Subject: [PATCH 9/9] max depth of the tree --- src/Practice.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 5cbed68..218ccf0 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -299,6 +299,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){ + return 0; + } + int maxDepth = 1; + + List children = tree.get(root); + + for(T child: children){ + int childDepth = maxDepth(tree, child); + if(childDepth +1 > maxDepth){ + maxDepth = childDepth + 1; + } + } + return maxDepth; } } \ No newline at end of file