From 31fee5669fdefb8a4b60e58cd156ab8a56e3082f Mon Sep 17 00:00:00 2001 From: sandeersson Date: Mon, 9 Jun 2025 11:17:22 -0700 Subject: [PATCH 1/3] Implemented DuplicateRemover --- src/DuplicateRemover.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/DuplicateRemover.java b/src/DuplicateRemover.java index 8d70003..54cac92 100644 --- a/src/DuplicateRemover.java +++ b/src/DuplicateRemover.java @@ -1,4 +1,7 @@ +import java.util.ArrayList; import java.util.List; +import java.util.Set; +import java.util.TreeSet; /** * The DuplicateRemover class provides a method to remove duplicate words @@ -14,8 +17,16 @@ public class DuplicateRemover { * @return a sorted List containing unique words from the input array */ public static List sortAndRemoveDuplicates(String[] words) { - // TODO - return null; + Set unique = new TreeSet<>(); + for (String word : words) { + unique.add(word); + } + List wordList = new ArrayList<>(); + for (String word : unique) { + wordList.add(word); + } + + return wordList; } public static void main(String[] args) { From 04ca2fb63ae619e7a8eb657958b2d675b8f96d93 Mon Sep 17 00:00:00 2001 From: sandeersson Date: Mon, 9 Jun 2025 12:28:39 -0700 Subject: [PATCH 2/3] Implemented UniqueCharacterChecker --- src/UniqueCharacterChecker.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/UniqueCharacterChecker.java b/src/UniqueCharacterChecker.java index 554ffc4..d4a0f77 100644 --- a/src/UniqueCharacterChecker.java +++ b/src/UniqueCharacterChecker.java @@ -1,3 +1,6 @@ +import java.util.HashSet; +import java.util.Set; + /** * The UniqueCharacterChecker class provides a method to check if all characters * in a given word are unique. @@ -14,7 +17,17 @@ public static boolean hasUniqueCharacters(String word) { // TODO: implement this! // Requirement: This must run in O(n) time, where n is the number of characters in the word // Hint: Stuck? Consider looking up "charAt" and seeing how it can help you - return false; + Set uniqueChar = new HashSet<>(); + + for (int i = 0; i < word.length(); i++) { + char currentChar = word.charAt(i); + if (uniqueChar.contains(currentChar)) { + return false; + } + uniqueChar.add(currentChar); + } + + return true; } public static void main(String[] args) { From 65b77a3c4d22d21ce598a7fb20a36462b33d2b72 Mon Sep 17 00:00:00 2001 From: sandeersson Date: Mon, 9 Jun 2025 13:39:32 -0700 Subject: [PATCH 3/3] Implemented CommonElementsFinder --- src/CommonElementsFinder.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/CommonElementsFinder.java b/src/CommonElementsFinder.java index fb88a4b..2829e5d 100644 --- a/src/CommonElementsFinder.java +++ b/src/CommonElementsFinder.java @@ -1,3 +1,4 @@ +import java.util.HashSet; import java.util.Set; /** @@ -15,7 +16,20 @@ public class CommonElementsFinder { */ public static Set findCommonElements(int[] array1, int[] array2) { // TODO - return null; + Set elements = new HashSet<>(); + Set commonElements = new HashSet<>(); + + for (int num : array1) { + elements.add(num); + } + + for (int num : array2) { + if (elements.contains(num)) { + commonElements.add(num); + } + } + + return commonElements; }