diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d0d412f..df09c66 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,16 +4,9 @@
-
-
-
-
-
-
-
+
+
-
-
@@ -80,18 +73,18 @@
- {
+ "keyToString": {
+ "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "git-widget-placeholder": "back__tracking",
+ "jdk.selected.JAVA_MODULE": "openjdk-21 (3)",
+ "onboarding.tips.debug.path": "/Users/subhamsantra/Projects/Interview/TheAlgorithm/low-level-design/src/main/java/com/subham/tbpp/Main.java",
+ "settings.editor.selected.configurable": "editor.preferences.completion"
}
-}]]>
+}
@@ -103,7 +96,7 @@
-
+
@@ -117,12 +110,12 @@
-
-
-
+
+
+
-
+
@@ -130,12 +123,12 @@
-
-
-
+
+
+
-
+
@@ -156,12 +149,12 @@
-
-
-
+
+
+
-
+
@@ -171,11 +164,11 @@
+
+
+
-
-
-
@@ -452,7 +445,23 @@
1725215225004
-
+
+
+ 1725217568204
+
+
+
+ 1725217568204
+
+
+
+ 1725812239746
+
+
+
+ 1725812239746
+
+
@@ -488,7 +497,9 @@
-
+
+
+
@@ -586,6 +597,17 @@
15
+
+ file://$PROJECT_DIR$/data-structures/src/main/java/com/thealgorithm/slidingwindow/MinimumWindowSubstring.java
+ 36
+
+
+
+
+ file://$PROJECT_DIR$/data-structures/src/main/java/com/thealgorithm/binsearch/CapacityToShipPackagesWithInDDays.java
+ 23
+
+
file://$PROJECT_DIR$/data-structures/src/main/java/com/thealgorithm/graph/CoursesII.java
44
@@ -598,7 +620,7 @@
file://$PROJECT_DIR$/data-structures/src/main/java/com/thealgorithm/backtracking/CombinationSumII.java
20
-
+
diff --git a/data-structures/src/main/java/com/thealgorithm/array/TheThreeSum.java b/data-structures/src/main/java/com/thealgorithm/array/TheThreeSum.java
new file mode 100644
index 0000000..40f37a0
--- /dev/null
+++ b/data-structures/src/main/java/com/thealgorithm/array/TheThreeSum.java
@@ -0,0 +1,10 @@
+package com.thealgorithm.array;
+
+/**
+ * @author: Subham Santra
+ */
+public class TheThreeSum {
+ public static void main(String[] args){
+
+ }
+}
diff --git a/data-structures/src/main/java/com/thealgorithm/binsearch/CapacityToShipPackagesWithInDDays.java b/data-structures/src/main/java/com/thealgorithm/binsearch/CapacityToShipPackagesWithInDDays.java
new file mode 100644
index 0000000..4f4580e
--- /dev/null
+++ b/data-structures/src/main/java/com/thealgorithm/binsearch/CapacityToShipPackagesWithInDDays.java
@@ -0,0 +1,83 @@
+package com.thealgorithm.binsearch;
+
+/**
+ * @author: Subham Santra
+ */
+public class CapacityToShipPackagesWithInDDays {
+
+ public int shipWithinDays(int[] weights, int days) {
+ int n = weights.length;
+ int[] prefixSum = new int[n + 1];
+ int weightMin = Integer.MIN_VALUE;
+
+ for (int i = 0; i < n; ++i) {
+ prefixSum[i + 1] = prefixSum[i] + weights[i];
+ weightMin = Math.max(weightMin, weights[i]);
+ }
+
+ int weightMax = prefixSum[prefixSum.length - 1];
+
+ int ans = Integer.MAX_VALUE;
+
+ while (weightMin <= weightMax) {
+ int mid = (weightMax + weightMin) / 2;
+ int checkDays = checkDays(prefixSum, mid, 1, n);
+ System.out.printf("midWeight = %d days = %d\n", mid, checkDays);
+ if (checkDays <= days) {
+ ans = mid;
+ weightMax = mid - 1;
+ } else {
+ weightMin = mid + 1;
+ }
+ }
+
+ return ans;
+ }
+
+ private int checkDays(int[] prefixSum, int weight, int lo, int hi) {
+ if (lo > hi) {
+ return 0;
+ }
+ if (lo == hi) {
+ return (prefixSum[lo] - prefixSum[lo - 1]) <= weight ? 1 : 0;
+ }
+ int pos = lowerBound(prefixSum, lo, weight);
+ if (pos == -1) {
+ return Integer.MAX_VALUE;
+ }
+ return 1 + checkDays(prefixSum, weight, pos + 1, hi);
+ }
+
+ private int lowerBound(int[] prefixSum, int lo, int target) {
+ int right = prefixSum.length - 1;
+ int left = lo;
+ int pos = -1;
+ while (left <= right) {
+ int mid = (left + right) / 2;
+ int midWeight = querySum(prefixSum, lo, mid);
+ if (midWeight <= target) {
+ pos = mid;
+ left = mid + 1;
+ } else {
+ right = mid - 1;
+ }
+ }
+ return pos;
+ }
+
+ private int querySum(int[] prefixSum, int lo, int hi) {
+ return prefixSum[hi] - prefixSum[lo - 1];
+ }
+
+ public static void main(String[] args) {
+ System.out.println(
+ new CapacityToShipPackagesWithInDDays().shipWithinDays(new int[] {3, 2, 2, 4, 1, 4}, 3));
+
+ System.out.println(
+ new CapacityToShipPackagesWithInDDays().shipWithinDays(new int[] {1, 2, 3, 1, 1}, 4));
+
+ System.out.println(
+ new CapacityToShipPackagesWithInDDays()
+ .shipWithinDays(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 5));
+ }
+}
diff --git a/data-structures/src/main/java/com/thealgorithm/binsearch/KokoEatingBananas.java b/data-structures/src/main/java/com/thealgorithm/binsearch/KokoEatingBananas.java
new file mode 100644
index 0000000..47b2eea
--- /dev/null
+++ b/data-structures/src/main/java/com/thealgorithm/binsearch/KokoEatingBananas.java
@@ -0,0 +1,47 @@
+package com.thealgorithm.binsearch;
+
+/**
+ * @author: Subham Santra
+ */
+public class KokoEatingBananas {
+ public int minEatingSpeed(int[] piles, int h) {
+ long hi = 0L;
+ long lo = 1;
+ for (int pile : piles) {
+ hi = Math.max(pile, hi);
+ }
+ // System.out.printf("Range speed %d to %d\n", lo, hi);
+ // start binary search
+ long minimumSpeed = 1L;
+ while (lo <= hi) {
+ long mid = ((hi - lo) >> 1) + lo;
+ long kokoFinishTime = kokoFinishTime(piles, mid);
+ // System.out.printf("finish time %d for speed %d\n", kokoFinishTime, mid);
+ if (kokoFinishTime <= h) {
+ // Taking exact same time or even less, we shall reduce speed and check
+ minimumSpeed = mid;
+ hi = mid - 1;
+ } else {
+ // Taking more time to finish, to reduce time, we need to increase speed
+ lo = mid + 1;
+ }
+ }
+ return (int) minimumSpeed;
+ }
+
+ long kokoFinishTime(int[] piles, long speed) {
+ long carry = 0L;
+ for (double pile : piles) {
+ carry += (long) Math.ceil(pile / speed);
+ }
+ return carry;
+ }
+
+ public static void main(String[] args) {
+ System.out.println(new KokoEatingBananas().minEatingSpeed(new int[] {3, 6, 7, 11}, 8));
+ System.out.println(new KokoEatingBananas().minEatingSpeed(new int[] {100}, 99));
+ System.out.println(
+ new KokoEatingBananas()
+ .minEatingSpeed(new int[] {805306368, 805306368, 805306368}, 1000000000));
+ }
+}
diff --git a/data-structures/src/main/java/com/thealgorithm/miscelleneous/WalkingRobotSimulation.java b/data-structures/src/main/java/com/thealgorithm/miscelleneous/WalkingRobotSimulation.java
new file mode 100644
index 0000000..acbee93
--- /dev/null
+++ b/data-structures/src/main/java/com/thealgorithm/miscelleneous/WalkingRobotSimulation.java
@@ -0,0 +1,61 @@
+package com.thealgorithm.miscelleneous;
+
+import com.thealgorithm.commons.Pair;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author: Subham Santra
+ */
+public class WalkingRobotSimulation {
+
+ static class Solution {
+ public int robotSim(int[] commands, int[][] obstacles) {
+
+ Set> obstacleSet = new HashSet<>();
+ for (int[] obs : obstacles) {
+ obstacleSet.add(Pair.of(obs[0], obs[1]));
+ }
+
+ int[] current = new int[2];
+
+ char direction = 'e';
+
+ int max = 0;
+
+ for (int command : commands) {
+ if (command < 0) {
+ direction = changeDirection(direction, command == -1);
+ } else {
+ // move(dir, current, command, obstacleSet);
+ int x = current[0];
+ int y = current[1];
+
+ for (int c = 1; c <= command; ++c) {
+ int xx = x + (direction == 'e' ? 1 : (direction == 'w' ? -1 : 0));
+ int yy = y + (direction == 'n' ? 1 : (direction == 's' ? -1 : 0));
+ if (obstacleSet.contains(Pair.of(xx, yy))) {
+ break;
+ }
+ current[0] = x = xx;
+ current[1] = y = yy;
+ max = Math.max(max, (int) Math.sqrt(x * x + y * y));
+ }
+ }
+ }
+ return max;
+ }
+
+ char changeDirection(char dir, boolean left) {
+ return switch (dir) {
+ case 'e' -> left ? 'n' : 's';
+ case 'n' -> left ? 'w' : 'e';
+ case 'w' -> left ? 's' : 'n';
+ case 's' -> left ? 'e' : 'w';
+ default -> '0';
+ };
+ }
+ }
+
+ public static void main(String[] args) {}
+}
diff --git a/data-structures/src/main/java/com/thealgorithm/rangeq/RangeSumSegmentTree.java b/data-structures/src/main/java/com/thealgorithm/rangeq/RangeSumSegmentTree.java
new file mode 100644
index 0000000..1a7e60f
--- /dev/null
+++ b/data-structures/src/main/java/com/thealgorithm/rangeq/RangeSumSegmentTree.java
@@ -0,0 +1,11 @@
+package com.thealgorithm.rangeq;
+
+
+/**
+ * @author: Subham Santra
+ */
+public class RangeSumSegmentTree {
+ public static void main(String[] args){
+
+ }
+}
diff --git a/data-structures/src/main/java/com/thealgorithm/slidingwindow/MinimumWindowSubstring.java b/data-structures/src/main/java/com/thealgorithm/slidingwindow/MinimumWindowSubstring.java
new file mode 100644
index 0000000..c41a13c
--- /dev/null
+++ b/data-structures/src/main/java/com/thealgorithm/slidingwindow/MinimumWindowSubstring.java
@@ -0,0 +1,65 @@
+package com.thealgorithm.slidingwindow;
+
+/**
+ * @author: Subham Santra
+ */
+public class MinimumWindowSubstring {
+ private static class Solution {
+ int ord(char c) {
+ return ('A' <= c && c <= 'Z') ? 26 + (c - 'A') : (c - 'a');
+ }
+
+ boolean isMatch(int[] w, int[] t) {
+ for (int i = 0; i < 52; ++i) {
+ if (t[i] != 0 && t[i] > w[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public String minWindow(String s, String t) {
+ int[] tScore = new int[52];
+ int[] wScore = new int[52];
+
+ for (int i = 0; i < t.length(); ++i) {
+ tScore[ord(t.charAt(i))]++;
+ }
+
+ int minWindowLength = Integer.MAX_VALUE;
+ int start = -1;
+ int end = -1;
+
+ for (int lo = 0, hi = 0; hi < s.length(); ++hi) {
+ //System.out.println("- " + s.charAt(hi) + " - " + s.substring(lo, hi + 1));
+ wScore[ord(s.charAt(hi))]++;
+
+ while (lo <= hi && isMatch(wScore, tScore)) {
+ //System.out.println(s.charAt(hi) + " - " + s.substring(lo, hi + 1));
+ if (minWindowLength > (hi - lo + 1)) {
+ minWindowLength = hi - lo + 1;
+ start = lo;
+ end = hi;
+ }
+ wScore[ord(s.charAt(lo))]--;
+ ++lo;
+ //System.out.println(s.charAt(hi) + " - " + s.substring(lo, hi + 1));
+ }
+ }
+
+ if (start > end) {
+ return "";
+ }
+ if (start == -1) {
+ return "";
+ }
+ return s.substring(start, end + 1);
+ }
+ }
+
+ public static void main(String[] args){
+ System.out.println(new Solution().minWindow("ADOBECODEBANC", "ABC"));
+ System.out.println(new Solution().minWindow("ACACBDEA", "ABC"));
+ System.out.println(new Solution().minWindow("ADOBECODEBANC", "ABC"));
+ }
+}