From 0737ada57797fd31af63e5c2988750869949f01f Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Mon, 28 Jul 2025 16:49:29 -0500 Subject: [PATCH 01/13] exercise solutions --- solutions/exercise solutions.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 solutions/exercise solutions.js diff --git a/solutions/exercise solutions.js b/solutions/exercise solutions.js new file mode 100644 index 0000000..e69de29 From cac378e458af8fba2fe5215f579e1a849930035e Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Sun, 31 Aug 2025 20:22:48 -0500 Subject: [PATCH 02/13] Two_sum: --- .idea/2025-software-dev-problem-set.iml | 9 +++++++++ solutions/.idea/.gitignore | 3 +++ solutions/.idea/misc.xml | 6 ++++++ solutions/.idea/modules.xml | 8 ++++++++ solutions/.idea/solutions.iml | 9 +++++++++ solutions/.idea/vcs.xml | 6 ++++++ 6 files changed, 41 insertions(+) create mode 100644 .idea/2025-software-dev-problem-set.iml create mode 100644 solutions/.idea/.gitignore create mode 100644 solutions/.idea/misc.xml create mode 100644 solutions/.idea/modules.xml create mode 100644 solutions/.idea/solutions.iml create mode 100644 solutions/.idea/vcs.xml diff --git a/.idea/2025-software-dev-problem-set.iml b/.idea/2025-software-dev-problem-set.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/2025-software-dev-problem-set.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/solutions/.idea/.gitignore b/solutions/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/solutions/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/solutions/.idea/misc.xml b/solutions/.idea/misc.xml new file mode 100644 index 0000000..31e1ebc --- /dev/null +++ b/solutions/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/solutions/.idea/modules.xml b/solutions/.idea/modules.xml new file mode 100644 index 0000000..7d282b8 --- /dev/null +++ b/solutions/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/solutions/.idea/solutions.iml b/solutions/.idea/solutions.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/solutions/.idea/solutions.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/solutions/.idea/vcs.xml b/solutions/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/solutions/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From 71e0cf4feced776c518a1cd9c248bd503698e63a Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Tue, 2 Sep 2025 19:43:26 -0500 Subject: [PATCH 03/13] group anagram --- solutions/.idea/solutions.iml | 4 +++- solutions/Group_Anagram.java | 19 +++++++++++++++++++ solutions/Two_Sum.java | 20 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 solutions/Group_Anagram.java create mode 100644 solutions/Two_Sum.java diff --git a/solutions/.idea/solutions.iml b/solutions/.idea/solutions.iml index d6ebd48..b107a2d 100644 --- a/solutions/.idea/solutions.iml +++ b/solutions/.idea/solutions.iml @@ -2,7 +2,9 @@ - + + + diff --git a/solutions/Group_Anagram.java b/solutions/Group_Anagram.java new file mode 100644 index 0000000..398ea5b --- /dev/null +++ b/solutions/Group_Anagram.java @@ -0,0 +1,19 @@ +import java.util.*; + +public class Group_Anagram { + public List> groupAnagrams(String[] strs) { + Map> res = new HashMap<>; + + for(String s : strs){ + int[] count = new int[26]; + for(char c : s.toCharArray()){ + count[c - 'a']++; + } + + String key = Arrays.toString(count); + res.putIfAbsent(key, new ArrayList<>); + res.get(key).add(s); + } + return new ArrayList<>(res.values()); + } +} diff --git a/solutions/Two_Sum.java b/solutions/Two_Sum.java new file mode 100644 index 0000000..bce825d --- /dev/null +++ b/solutions/Two_Sum.java @@ -0,0 +1,20 @@ +import java.util.HashMap; + +public class Two_Sum { + public int[] twoSum(int[] nums, int target) { + HashMap prevMap = new HashMap<>(); + + for (int i = 0; i < nums.length; i++) { + int num = nums[i]; + int diff = target - num; + + + if (prevMap.containsKey(diff)) { + return new int[]{prevMap.get(diff), i}; + } + prevMap.put(num, i); + } + return new int[]{}; + } + } + From 6088ea368a20b728287257467e9ebc4eea04473c Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Wed, 3 Sep 2025 13:56:01 -0500 Subject: [PATCH 04/13] Top Freq k --- solutions/Group_Anagram.java | 6 +++--- solutions/TopKFreq.java | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 solutions/TopKFreq.java diff --git a/solutions/Group_Anagram.java b/solutions/Group_Anagram.java index 398ea5b..05fac4b 100644 --- a/solutions/Group_Anagram.java +++ b/solutions/Group_Anagram.java @@ -4,14 +4,14 @@ public class Group_Anagram { public List> groupAnagrams(String[] strs) { Map> res = new HashMap<>; - for(String s : strs){ + for (String s : strs) { int[] count = new int[26]; - for(char c : s.toCharArray()){ + for (char c : s.toCharArray()) { count[c - 'a']++; } String key = Arrays.toString(count); - res.putIfAbsent(key, new ArrayList<>); + res.putIfAbsent(key, new ArrayList()); res.get(key).add(s); } return new ArrayList<>(res.values()); diff --git a/solutions/TopKFreq.java b/solutions/TopKFreq.java new file mode 100644 index 0000000..5ff6092 --- /dev/null +++ b/solutions/TopKFreq.java @@ -0,0 +1,35 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +class Solution { + public int[] topKFrequent(int[] nums, int k){ + Map count = new HashMap<>(); + + for(int n : nums){ + count.put(n, count.getOrDefault(n, 0) + 1); + } + + List[] freq = new List[nums.length + 1]; + for(int i = 0; i < freq.length; i++){ + freq[i] = new ArrayList<>; + } + + for(Map.Entry entry : count.entrySet()){ + freq[entry.getValue()].add(entry.getKey()); + } + + int[] res = new int[k]; + int index = 0; + for(int i = freq.length - 1; i > 0 && index < k; i--){ + for(int n : freq[i]) { + res[index++] = n; + if(index == k){ + return res; + } + } + } + return res; + } +} From 932d089847e1b8b0a29e0aaba3f9bc3a9ef45e2f Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Wed, 3 Sep 2025 20:53:39 -0500 Subject: [PATCH 05/13] Product of array --- solutions/ProductofArrayXItself.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 solutions/ProductofArrayXItself.java diff --git a/solutions/ProductofArrayXItself.java b/solutions/ProductofArrayXItself.java new file mode 100644 index 0000000..7345fa9 --- /dev/null +++ b/solutions/ProductofArrayXItself.java @@ -0,0 +1,17 @@ +public class ProductofArrayXItself { + + int n = nums.length; + int[] res = new int[n]; + + int res[0] = 1; + for(int i = 1; i < n; i++){ + res[i] = res[i - 1] * nums[i - 1]; + } + + int postfix = 1; + for(int i = n - 1; i >= 0; i--){ + res[i] *= postfix; + postfix *= nums[i]; + } + return res; +} From e54e0dbd38baec0e74223f0dd61661ea493579a5 Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Thu, 4 Sep 2025 18:53:06 -0500 Subject: [PATCH 06/13] valid sudoku --- solutions/ValidSydoku.java | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 solutions/ValidSydoku.java diff --git a/solutions/ValidSydoku.java b/solutions/ValidSydoku.java new file mode 100644 index 0000000..69a3add --- /dev/null +++ b/solutions/ValidSydoku.java @@ -0,0 +1,39 @@ +import java.util.HashSet; +import java.util.Set; + +class Solution { + public boolean isValidSudoku(char[][] board) { + + for (int row = 0; row < 9; row++) { + Set seen = new HashSet<>(); + for (int i = 0; i < 9; i++) { + if (board[row][i] == '.') continue; + if (seen.contains(board[row][i])) return false; + seen.add(board[row][i]); + } + } + + for (int col = 0; col < 9; col++) { + Set seen = new HashSet<>(); + for (int i = 0; i < 9; i++) { + if (board[i][col] == '.') continue; + if (seen.contains(board[i][col])) return false; + seen.add(board[i][col]); + } + } + + for (int square = 0; square < 9; square++) { + Set seen = new HashSet<>(); + for (int i = 0; i < 9; i++) { + for (int j = 0; j < 9; j++) { + int row = (square / 3) * 3 + i; + int col = (square % 3) * 3 + j; + if (board[row][col] == '.') continue; + if (seen.contains(board[row][col])) return false; + seen.add(board[row][col]); + } + } + } + return true; + } +} \ No newline at end of file From 9c9080bf001b620a0f34af357e1a5b25b11fb957 Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Thu, 4 Sep 2025 18:56:06 -0500 Subject: [PATCH 07/13] Longest conseq seq branch --- solutions/LConsSeq.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 solutions/LConsSeq.java diff --git a/solutions/LConsSeq.java b/solutions/LConsSeq.java new file mode 100644 index 0000000..6e1050a --- /dev/null +++ b/solutions/LConsSeq.java @@ -0,0 +1,5 @@ +class Solution { + public int longestConsecutive(int[] nums) { + + } +} \ No newline at end of file From bad6edaafb3f2aafac88409f5d375d31efb049a3 Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Tue, 9 Sep 2025 20:34:48 -0500 Subject: [PATCH 08/13] Longest Conseq Sequence --- solutions/LConsSeq.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/solutions/LConsSeq.java b/solutions/LConsSeq.java index 6e1050a..b386149 100644 --- a/solutions/LConsSeq.java +++ b/solutions/LConsSeq.java @@ -1,5 +1,19 @@ +import java.util.HashMap; +import java.util.Map; + class Solution { public int longestConsecutive(int[] nums) { + Map mp = new HashMap<>(); + int res = 0; + for(int num : nums){ + if (!mp.containsKey(num)){ + mp.put(num, mp.getOrDefault(num - 1, 0) + mp.getOrDefault(num + 1, 0) + 1); + mp.put(num - mp.getOrDefault(num - 1, 0), mp.get(num)); + mp.put(num + mp.getOrDefault(num + 1, 0), mp.get(num)); + res = Math.max(res, mp.get(num)); + } + } + return res; } } \ No newline at end of file From 6cd78286fff6fcf19589e448b11ba26868db3a9d Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Wed, 10 Sep 2025 17:39:46 -0500 Subject: [PATCH 09/13] valid palindrome java --- solutions/ValidPalindrome.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 solutions/ValidPalindrome.java diff --git a/solutions/ValidPalindrome.java b/solutions/ValidPalindrome.java new file mode 100644 index 0000000..7efa143 --- /dev/null +++ b/solutions/ValidPalindrome.java @@ -0,0 +1,25 @@ +class Solution { + public boolean isPalindrome(String s) { + int l = 0, r = s.length() - 1; + + while(l < r){ + while(l < r && !alphaNum(s.charAt(l))){ + l++; + } + while(r > l && !alphaNum(s.charAt(r))){ + r--; + } + if(Character.toLowerCase(s.charAt(l)) != Character.toLowerCase(s.charAt(r))){ + return false; + } + l++; r--; + } + return true; + } + + public boolean alphaNum(char c){ + return (c >= 'A' && c <= 'Z' || + c >= 'a' && c <= 'z' || + c >= '0' && c <= '9'); + } + } From eaf6f9b24c33d9956732e4339f0b04c55dc8ee43 Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Wed, 10 Sep 2025 18:02:29 -0500 Subject: [PATCH 10/13] Two Sum II java --- solutions/TwoSum2.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solutions/TwoSum2.java diff --git a/solutions/TwoSum2.java b/solutions/TwoSum2.java new file mode 100644 index 0000000..01c635a --- /dev/null +++ b/solutions/TwoSum2.java @@ -0,0 +1,18 @@ +class Solution { + public int[] twoSum(int[] numbers, int target) { + int l = 0, r = numbers.length - 1; + + while(l < r){ + int curSum = numbers[l] + numbers[r]; + + if(curSum > target){ + r--; + } else if (curSum < target){ + l++; + } else { + return new int[] = {l + 1, r + 1}; + } + } + return new int[0]; + } +} \ No newline at end of file From c277382e61ce661dab27d43924b2b0fa317d8ab4 Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Thu, 11 Sep 2025 15:57:49 -0500 Subject: [PATCH 11/13] three sum --- solutions/Three_Sum.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 solutions/Three_Sum.java diff --git a/solutions/Three_Sum.java b/solutions/Three_Sum.java new file mode 100644 index 0000000..4a6946f --- /dev/null +++ b/solutions/Three_Sum.java @@ -0,0 +1,32 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +class Solution { + public List> threeSum(int[] nums) { + Arrays.sort(nums); + List> res = new ArrayList<>(); + for(int i = 0; i < nums.length; i++){ + if(nums[i] > 0) break; + if(i > 0 && nums[i] == nums[i - 1]) continue; + + int l = i + 1, r = nums.length - 1; + while(l < r){ + int sum = nums[i] + nums[l] + nums[r]; + if(sum > 0){ + r--; + } else if (sum < 0){ + l++; + } else { + res.add(Arrays.asList(nums[i], nums[l], nums[r])); + l++; + r--; + while(l < r && (nums[l] == nums[l - 1]){ + l++; + } + } + } + } + return res; + } +} \ No newline at end of file From c079c4d24b53a860d947591a02cc81b850609331 Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Tue, 16 Sep 2025 20:10:20 -0500 Subject: [PATCH 12/13] contain water --- solutions/ContainerWMostWater.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solutions/ContainerWMostWater.java diff --git a/solutions/ContainerWMostWater.java b/solutions/ContainerWMostWater.java new file mode 100644 index 0000000..373dee9 --- /dev/null +++ b/solutions/ContainerWMostWater.java @@ -0,0 +1,18 @@ +class Solution { + public int maxArea(int[] height) { + int l = 0; + int r = height.length - 1; + int res = 0; + + while(l < r){ + int area = Math.min(height[l], height[r]) * (r - l); + res = Math.max(res, area); + if (height[l] <= height[r]) { + l++; + }else{ + r--; + } + } + return res; + } +} \ No newline at end of file From 77c44d534b808006fe66542db906689a1b802ec9 Mon Sep 17 00:00:00 2001 From: StaceyO21 Date: Tue, 16 Sep 2025 20:42:40 -0500 Subject: [PATCH 13/13] isValid --- solutions/Valid_Parentheses.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 solutions/Valid_Parentheses.java diff --git a/solutions/Valid_Parentheses.java b/solutions/Valid_Parentheses.java new file mode 100644 index 0000000..48da96a --- /dev/null +++ b/solutions/Valid_Parentheses.java @@ -0,0 +1,5 @@ +class Solution { + public boolean isValid(String s) { + + } +} \ No newline at end of file