From 549f9220a50b864d9fa777bd58ac327e807712de Mon Sep 17 00:00:00 2001 From: Niko_Butenko <174657090+Butenkite@users.noreply.github.com> Date: Tue, 23 Sep 2025 11:32:38 -0700 Subject: [PATCH 01/11] completed oddsum --- src/Practice.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 01da8d0..bd78125 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -11,7 +11,14 @@ public class Practice { * @return the sum of the odd numbers in the array */ public static int oddSum(int[] nums) { - return 0; + int sum = 0; + if(nums == null) return sum; + for(int num : nums){ + if(num%2 == 1 || num%2 == -1){ + sum += num; + } + } + return sum; } /** From 0e5efc8a8498533c11e8f2165b9845a11c49e1df Mon Sep 17 00:00:00 2001 From: Butenkite Date: Wed, 24 Sep 2025 17:38:36 -0700 Subject: [PATCH 02/11] Partial shortest word --- src/Practice.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Practice.java b/src/Practice.java index bd78125..97edac2 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -33,6 +33,14 @@ public static int oddSum(int[] nums) { * @throws NullPointerException if words is null */ public static String shortestWord(Set words) { + int wordLength = Integer.MAX_VALUE; + String wordChamp = ""; + for (String word : words) { + if(word.length() < wordLength){ + wordChamp = word; + wordLength = word.length(); + } + } return null; } From 0de0a54cba587daf204fc564f9e02ffe051fce5c Mon Sep 17 00:00:00 2001 From: Butenkite Date: Wed, 24 Sep 2025 18:04:29 -0700 Subject: [PATCH 03/11] adults implemented --- src/Practice.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 97edac2..dedc647 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -1,3 +1,4 @@ +import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -54,7 +55,13 @@ public static String shortestWord(Set words) { * @throws NullPointerException if ages is null */ public static Set adults(Map ages) { - return null; + Set returnable = new HashSet<>(); + for(String name : ages.keySet()){ + if(ages.get(name) >= 18){ + returnable.add(name); + } + } + return returnable; } /** From 6b9752a6e39a43f68a1eb37b53549245231b287b Mon Sep 17 00:00:00 2001 From: Butenkite Date: Wed, 24 Sep 2025 18:10:13 -0700 Subject: [PATCH 04/11] Biggest number implemented --- src/Practice.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index dedc647..3f961a1 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -72,7 +72,14 @@ public static Set adults(Map ages) { * @throws IllegalArgumentException if head is null */ public static int biggestNumber(ListNode head) { - return 0; + int kingNum = Integer.MIN_VALUE; + while(head != null){ + if(head.data > kingNum){ + kingNum = head.data; + } + head = head.next; + } + return kingNum; } /** From c159336b962ef1f7afd6186c7810501cf38310ec Mon Sep 17 00:00:00 2001 From: Butenkite Date: Wed, 24 Sep 2025 18:23:13 -0700 Subject: [PATCH 05/11] Frequency implemented --- src/Practice.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 3f961a1..9438138 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -1,3 +1,4 @@ +import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -96,7 +97,17 @@ public static int biggestNumber(ListNode head) { * @return a frequency map of values in the list */ public static Map frequencies(ListNode head) { - return null; + Map returnable = new HashMap<>(); + while(head != null){ + if(!returnable.containsKey(head.data)){ + returnable.put(head.data, 1); + } + else{ + returnable.replace(head.data, returnable.get(head.data)+1); + } + head = head.next; + } + return returnable; } From 806799d2407535c0a17c08c75fdb07bae94a1b86 Mon Sep 17 00:00:00 2001 From: Butenkite Date: Wed, 24 Sep 2025 19:08:59 -0700 Subject: [PATCH 06/11] level count implemented --- src/Practice.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 9438138..d5e49a1 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -120,7 +120,14 @@ public static Map frequencies(ListNode head) { * @return the number of levels in the tree */ public static int levelCount(BinaryTreeNode root) { - return 0; + return levelCountHelper(root, 0); + } + + public static int levelCountHelper(BinaryTreeNode root, int level) { + if (root == null) return level; + int leftLevel = levelCountHelper(root.left, level + 1); + int rightLevel = levelCountHelper(root.right, level + 1); + return Math.max(leftLevel, rightLevel); } From a37a923b4ff6acf2e64013f923481c721051d943 Mon Sep 17 00:00:00 2001 From: Butenkite Date: Wed, 24 Sep 2025 19:51:57 -0700 Subject: [PATCH 07/11] SumAtLevel Implemented --- src/Practice.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index d5e49a1..17e5755 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -155,7 +155,13 @@ public static int levelCountHelper(BinaryTreeNode root, int level) { * @return the sum of the nodes at the given level */ public static int sumAtLevel(BinaryTreeNode root, int level) { - return 0; + return sumAtLevelHelper(root, level); + } + + public static int sumAtLevelHelper(BinaryTreeNode root, int level) { + if (root == null) return 0; + if(level == 1) return root.data; + return sumAtLevelHelper(root.left, level - 1) + sumAtLevelHelper(root.right, level - 1); } From c78a9f5eebc593161a794b1f99bae31808161be8 Mon Sep 17 00:00:00 2001 From: Butenkite Date: Wed, 24 Sep 2025 20:11:05 -0700 Subject: [PATCH 08/11] Sum Match implemented --- src/Practice.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Practice.java b/src/Practice.java index 17e5755..091d1d8 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -176,9 +176,28 @@ public static int sumAtLevelHelper(BinaryTreeNode root, int level) { * @return true if the sums are equal, false otherwise */ public static boolean sumMatch(BinaryTreeNode root, ListNode head) { + int sumList = sumMatchList(head); + int sumTree = sumMatchTree(root); + if(sumList == sumTree) return true; return false; } + public static int sumMatchList(ListNode head) { + int sum = 0; + while(head != null){ + sum += head.data; + head = head.next; + } + return sum; + } + + public static int sumMatchTree(BinaryTreeNode root) { + if(root == null) return 0; + int left = sumMatchTree(root.left); + int right = sumMatchTree(root.right); + return root.data + left + right; + } + /** * Returns the sum of all the vertices in a graph that are reachable from a given * starting vertex. From 649a25a3d4c3fa8f925b2e0de6b4b0e4c9078e0f Mon Sep 17 00:00:00 2001 From: Butenkite Date: Wed, 24 Sep 2025 21:15:00 -0700 Subject: [PATCH 09/11] graphsum complete --- src/Practice.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index 091d1d8..e772bf2 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -208,7 +208,21 @@ public static int sumMatchTree(BinaryTreeNode root) { * @return the sum of all the vertices */ public static int graphSum(Vertex start) { - return 0; + if(start == null) return 0; + int sum = 0; + Set> visited = new HashSet<>(); + graphSumHelper(start, visited); + for(Vertex cur : visited){ + sum+= cur.data; + } + return sum; + } + public static void graphSumHelper(Vertex start, Set> visited){ + if (start == null || visited.contains(start)) return; + visited.add(start); + for(Vertex neighbor : start.neighbors){ + graphSumHelper(neighbor, visited); + } } /** From dc072cb0337900e3a522e2a32c8df847fab2a5a0 Mon Sep 17 00:00:00 2001 From: Butenkite Date: Wed, 24 Sep 2025 21:23:09 -0700 Subject: [PATCH 10/11] finished sinkCount --- src/Practice.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index e772bf2..be37911 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -234,6 +234,23 @@ public static void graphSumHelper(Vertex start, Set> vi * @return the count of vertices with outdegree 0 */ public static int sinkCount(Vertex start) { - return 0; + if(start == null) return 0; + int sum = 0; + Set> visited = new HashSet<>(); + sinkCountHelper(start, visited); + for(Vertex cur : visited){ + if(cur.neighbors.size() == 0 || cur.neighbors == null){ + sum++; + } + } + return sum; + } + + public static void sinkCountHelper(Vertex start, Set> visited){ + if(start == null || visited.contains(start)) return; + visited.add(start); + for(Vertex neighbor : start.neighbors){ + sinkCountHelper(neighbor, visited); + } } } \ No newline at end of file From af190408c78cea37c140127373e90b5791fe5f5d Mon Sep 17 00:00:00 2001 From: Butenkite Date: Wed, 24 Sep 2025 21:43:55 -0700 Subject: [PATCH 11/11] Quenched Atlast --- src/Practice.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index be37911..85274f1 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -42,8 +42,13 @@ public static String shortestWord(Set words) { wordChamp = word; wordLength = word.length(); } + else if(word.length() == wordLength){ + if(word.compareTo(wordChamp) < 0){ + wordChamp = word; + } + } } - return null; + return wordChamp; } /**