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]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting left pointer at 1 instead of 0.
Using negative index which is invalid.
✗ 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 (target_freq[s[right]] [1] 0) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which only checks equality, not presence.
Using '<' which is incorrect for frequency check.
✗ Incorrect
We check if the frequency of the character is greater than zero to know if it is needed.
3fill in blank
hardFix the error in the condition to shrink the window when all characters are matched.
DSA C
while (formed [1] required) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' which causes incorrect shrinking.
Using '<' or '>' which do not represent the correct condition.
✗ Incorrect
We shrink the window only when the number of formed characters equals the required count.
4fill in blank
hardFill both blanks to update the minimum window size and start index.
DSA C
if (right - left + 1 [1] min_len) { min_len = right - left + 1; min_start = [2]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' causes wrong window size update.
Setting min_start to right instead of left.
✗ Incorrect
We update min_len if the current window is smaller and record the start index as left.
5fill in blank
hardFill all three blanks to correctly update the frequency map and formed count when shrinking the window.
DSA C
char c = s[left]; window_freq[c]--; if (window_freq[c] [1] target_freq[c]) { formed [2]; } left [3] 1;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' in frequency comparison.
Incrementing formed instead of decrementing.
Moving left pointer backward instead of forward.
✗ Incorrect
When the window frequency falls below target, formed decreases; left pointer moves right.
