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 at 1 skips the first character.
Using -1 causes invalid indexing.
✗ 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 C++
if (formed == required) [1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using continue skips shrinking logic.
Returning true ends the function prematurely.
✗ Incorrect
When the window contains all required characters, we can try to shrink it, so we break the current expansion loop.
3fill in blank
hardFix the error in updating the minimum window length.
DSA C++
if (end - start + 1 < minLen) { minLen = [1]; minStart = start; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using start - end + 1 results in negative length.
Adding start and end incorrectly calculates length.
✗ Incorrect
The window length is calculated as end - start + 1 because indices are zero-based and inclusive.
4fill in blank
hardFill both blanks to update the character count and move the left pointer.
DSA C++
windowCounts[s[start]] [1]; start [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing the count instead of decrementing.
Moving start backward instead of forward.
✗ Incorrect
We decrease the count of the character at start and then move start forward by incrementing it.
5fill in blank
hardFill both blanks to build the result substring from the original string.
DSA C++
return minLen == INT_MAX ? "" : s.[1](minStart, [2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using size or length as the second argument instead of minLen.
Using incorrect function name for substring.
✗ Incorrect
Use substr to get the substring starting at minStart with length minLen.
