Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the left pointer for the sliding window.
DSA C#
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 character is in the target frequency map.
DSA C#
if (targetFreq.ContainsKey(s[[1]]))
Attempts:
3 left
💡 Hint
Common Mistakes
Using left pointer instead of right causes wrong character checks.
Using undefined variable i or count causes errors.
✗ Incorrect
We check the character at the right pointer because the window expands from right to left.
3fill in blank
hardFix the error in updating the window counts after including a character.
DSA C#
windowCounts[s[[1]]] = windowCounts.GetValueOrDefault(s[[1]], 0) [2] 1;
Attempts:
3 left
💡 Hint
Common Mistakes
Using left pointer instead of right.
Subtracting instead of adding causes wrong counts.
✗ Incorrect
We increase the count of the character at the right pointer by 1 in the window counts.
4fill in blank
hardFill both blanks to update the minimum window length and start index.
DSA C#
if (right - left + 1 < [1]) { minLen = right - left + 1; start = [2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting start to right instead of left.
Not updating minLen causes incorrect results.
✗ Incorrect
We update minLen with the new smaller window size and start with the current left pointer.
5fill in blank
hardFill all three blanks to shrink the window and update counts correctly.
DSA C#
char c = s[[1]]; windowCounts[c] = windowCounts[c] [2] 1; left = [3] + 1;
Attempts:
3 left
💡 Hint
Common Mistakes
Using right pointer instead of left to remove character.
Adding instead of subtracting counts.
Not moving left pointer forward.
✗ Incorrect
We remove the character at left from the window by decreasing its count and move left pointer forward.
