Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the left pointer for the sliding window.
DSA Java
int left = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Starting left pointer at 1 skips the first character.
Using -1 causes index errors.
Setting left to s.length() is out of bounds.
✗ Incorrect
The left pointer starts at index 0 to begin scanning the string from the start.
2fill in blank
mediumComplete the code to check if the current window contains all required characters.
DSA Java
if (formed == required) [1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or brackets instead of braces causes syntax errors.
Missing braces leads to only one statement being conditionally executed.
✗ Incorrect
The if statement requires curly braces to start the block of code to execute when condition is true.
3fill in blank
hardFix the error in updating the character count in the window.
DSA Java
windowCounts.put(c, windowCounts.getOrDefault(c, 0) [1] 1);
Attempts:
3 left
💡 Hint
Common Mistakes
Using minus decreases count incorrectly.
Multiplying or dividing does not update count properly.
✗ Incorrect
We add 1 to the current count of character c in the window.
4fill in blank
hardFill both blanks to correctly update the minimum window size and start index.
DSA Java
if (right - left + 1 < [1]) { minLen = right - left + 1; [2] = left; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using maxLen instead of minLen reverses logic.
Updating end instead of start causes wrong window tracking.
✗ Incorrect
We update minLen with the smaller window size and start with the current left index.
5fill in blank
hardFill all three blanks to correctly shrink the window and update counts.
DSA Java
char c = s.charAt([1]); windowCounts.put(c, windowCounts.getOrDefault(c, 0) [2] 1); if (windowCounts.get(c) < dictT.getOrDefault(c, 0)) { [3]--; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using right instead of left causes wrong character removal.
Using plus instead of minus causes incorrect count update.
Decreasing wrong variable instead of formed breaks logic.
✗ Incorrect
We get the character at left, subtract 1 from its count, and decrease formed when the count is less than required.
