0
0
DSA Typescriptprogramming~10 mins

Minimum Number of Platforms in DSA Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to sort the arrival times array.

DSA Typescript
arrivals.sort((a, b) => a [1] b);
Drag options to blanks, or click blank then click option'
A+
B/
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' causes incorrect sorting.
Using '*' or '/' in compare function causes runtime errors.
2fill in blank
medium

Complete the code to increment the platform count when a train arrives before the earliest departure.

DSA Typescript
if (arrivals[i] [1] departures[j]) {
  platforms++;
  i++;
}
Drag options to blanks, or click blank then click option'
A<
B>=
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' causes wrong platform count.
Using '<=' includes equal times incorrectly.
3fill in blank
hard

Fix the error in updating the maximum platforms needed.

DSA Typescript
maxPlatforms = Math.[1](maxPlatforms, platforms);
Drag options to blanks, or click blank then click option'
Amin
Bmax
Cabs
Dround
Attempts:
3 left
💡 Hint
Common Mistakes
Using Math.min causes incorrect minimum platform count.
Using Math.abs or Math.round is unrelated to max calculation.
4fill in blank
hard

Fill both blanks to correctly move pointers when a train departs.

DSA Typescript
else {
  platforms[1];
  j[2];
}
Drag options to blanks, or click blank then click option'
A--
B++
C+=
D-=
Attempts:
3 left
💡 Hint
Common Mistakes
Increasing platforms on departure causes errors.
Moving pointers in wrong direction breaks logic.
5fill in blank
hard

Fill all three blanks to complete the function that returns minimum platforms needed.

DSA Typescript
function minPlatforms(arrivals: number[], departures: number[]): number {
  arrivals.sort((a, b) => a [1] b);
  departures.sort((a, b) => a [2] b);
  let platforms = 0, maxPlatforms = 0;
  let i = 0, j = 0;
  while (i < arrivals.length && j < departures.length) {
    if (arrivals[i] [3] departures[j]) {
      platforms++;
      i++;
      maxPlatforms = Math.max(maxPlatforms, platforms);
    } else {
      platforms--;
      j++;
    }
  }
  return maxPlatforms;
}
Drag options to blanks, or click blank then click option'
A-
B<
C>
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' in sort causes string concatenation errors.
Using '>' in if condition reverses logic.