Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to select the next interval with the earliest finish time.
DSA Typescript
intervals.sort((a, b) => a.end [1] b.end); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of subtraction in the sort comparator.
Sorting by start time instead of end time.
✗ Incorrect
Sorting intervals by their end time requires subtracting b.end from a.end to get ascending order.
2fill in blank
mediumComplete the code to check if the current interval starts after the last selected interval ends.
DSA Typescript
if (interval.start [1] lastSelectedEnd) { selected.push(interval); lastSelectedEnd = interval.end; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using >= instead of >, which allows overlapping intervals.
Using < or <=, which is incorrect for this condition.
✗ Incorrect
We select the interval only if it starts after the last selected interval ends, so interval.start > lastSelectedEnd.
3fill in blank
hardFix the error in the greedy coin change algorithm that fails for non-standard coin sets.
DSA Typescript
function greedyChange(amount: number, coins: number[]): number[] {
coins.sort((a, b) => b - a);
const result: number[] = [];
for (const coin of coins) {
while (amount [1] coin) {
amount -= coin;
result.push(coin);
}
}
return result;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of >= causes missing exact matches.
Using < or <= causes infinite loops or no coins used.
✗ Incorrect
The loop should run while amount is greater than or equal to the coin value to use that coin.
4fill in blank
hardFill both blanks to create a dictionary comprehension that filters words longer than 3 characters and maps to their lengths.
DSA Typescript
const lengths = { [1]: [2] for (const word of words) if (word.length > 3) }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the condition as a key or value.
Using uppercase words as keys instead of original words.
✗ Incorrect
The key is the word itself, and the value is its length.
5fill in blank
hardFill all three blanks to create a map filtering entries with positive values and mapping keys to uppercase.
DSA Typescript
const filteredMap = new Map(Object.entries(data) .filter(([[1], [2]]) => [2] > 0) .map(([[1], [2]]) => [[3], [2]]) );
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using value.toUpperCase() which is invalid if value is a number.
Mixing up key and value in filter or map.
✗ Incorrect
We destructure entries into key and value, filter by value > 0, and map keys to uppercase with their values.