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..b107a2d --- /dev/null +++ b/solutions/.idea/solutions.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ 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 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 diff --git a/solutions/Group_Anagram.java b/solutions/Group_Anagram.java new file mode 100644 index 0000000..05fac4b --- /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/LConsSeq.java b/solutions/LConsSeq.java new file mode 100644 index 0000000..b386149 --- /dev/null +++ b/solutions/LConsSeq.java @@ -0,0 +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 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; +} 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 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; + } +} 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 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[]{}; + } + } + 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'); + } + } 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 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 diff --git a/solutions/exercise solutions.js b/solutions/exercise solutions.js new file mode 100644 index 0000000..e69de29