Bird
Raised Fist0
DSA Goprogramming~20 mins

Minimum Number of Platforms in DSA Go - Practice Problems & Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Minimum Platforms Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of Minimum Platforms Calculation
What is the output of the following Go code that calculates the minimum number of platforms needed for given train arrival and departure times?
DSA Go
package main

import (
	"fmt"
	"sort"
)

func minPlatforms(arrivals []int, departures []int) int {
	sort.Ints(arrivals)
	sort.Ints(departures)

	platformsNeeded := 0
	maxPlatforms := 0
	i, j := 0, 0

	for i < len(arrivals) && j < len(departures) {
		if arrivals[i] <= departures[j] {
			platformsNeeded++
			if platformsNeeded > maxPlatforms {
				maxPlatforms = platformsNeeded
			}
			i++
		} else {
			platformsNeeded--
			j++
		}
	}

	return maxPlatforms
}

func main() {
	arrivals := []int{900, 940, 950, 1100, 1500, 1800}
	departures := []int{910, 1200, 1120, 1130, 1900, 2000}
	fmt.Println(minPlatforms(arrivals, departures))
}
A3
B2
C4
D5
Attempts:
2 left
💡 Hint
Think about how many trains overlap at the same time after sorting arrivals and departures.
🧠 Conceptual
intermediate
1:00remaining
Understanding the Core Idea of Minimum Platforms
Which of the following best describes the main idea behind finding the minimum number of platforms needed at a railway station?
AFind the longest train arrival time.
BCalculate the total number of trains arriving in a day.
CCount the maximum number of trains present at the station at the same time.
DSum all the arrival and departure times.
Attempts:
2 left
💡 Hint
Think about what causes the need for more platforms.
🔧 Debug
advanced
2:00remaining
Identify the Error in Platform Calculation Code
What error will the following Go code produce when calculating minimum platforms?
DSA Go
package main

import (
	"fmt"
	"sort"
)

func minPlatforms(arrivals []int, departures []int) int {
	sort.Ints(arrivals)
	sort.Ints(departures)

	platformsNeeded := 0
	maxPlatforms := 0
	i, j := 0, 0

	for i < len(arrivals) || j < len(departures) {
		if arrivals[i] <= departures[j] {
			platformsNeeded++
			if platformsNeeded > maxPlatforms {
				maxPlatforms = platformsNeeded
			}
			i++
		} else {
			platformsNeeded--
			j++
		}
	}

	return maxPlatforms
}

func main() {
	arrivals := []int{900, 940, 950, 1100, 1500, 1800}
	departures := []int{910, 1200, 1120, 1130, 1900, 2000}
	fmt.Println(minPlatforms(arrivals, departures))
}
Areturns incorrect minimum platforms
Bcompilation error due to missing import
Cinfinite loop
Druntime error: index out of range
Attempts:
2 left
💡 Hint
Check the loop condition and array indexing carefully.
🚀 Application
advanced
1:30remaining
Minimum Platforms for Overlapping Trains
Given arrival times [1000, 1010, 1025, 1030] and departure times [1020, 1035, 1040, 1050], what is the minimum number of platforms required?
A3
B1
C4
D2
Attempts:
2 left
💡 Hint
Sort the times and count overlaps carefully.
📝 Syntax
expert
1:30remaining
Identify Syntax Error in Go Code for Minimum Platforms
Which option contains a syntax error in this Go code snippet for minimum platforms?
DSA Go
package main

import (
	"fmt"
	"sort"
)

func minPlatforms(arrivals []int, departures []int) int {
	sort.Ints(arrivals)
	sort.Ints(departures)

	platformsNeeded := 0
	maxPlatforms := 0
	i, j := 0, 0

	for i < len(arrivals) && j < len(departures) {
		if arrivals[i] <= departures[j] {
			platformsNeeded++
			if platformsNeeded > maxPlatforms {
				maxPlatforms = platformsNeeded
			}
			i++
		} else {
			platformsNeeded--
			j++
		}
	}

	return maxPlatforms
}

func main() {
	arrivals := []int{900, 940, 950, 1100, 1500, 1800}
	departures := []int{910, 1200, 1120, 1130, 1900, 2000}
	fmt.Println(minPlatforms(arrivals, departures))
}
AMissing colon after if condition
BNo syntax error; code is correct
CUsing '||' instead of '&&' in for loop condition
DIncorrect variable declaration for i, j
Attempts:
2 left
💡 Hint
Check the if statement syntax carefully.

Practice

(1/5)
1. What does the "Minimum Number of Platforms" problem ask you to find given train arrival and departure times?
easy
A. The earliest train arrival time
B. The total number of trains arriving in a day
C. The longest time a train stays on a platform
D. The least number of platforms needed so no train waits

Solution

  1. Step 1: Understand the problem context

    The problem wants to find how many platforms are needed so that no train has to wait for another to leave.
  2. Step 2: Identify the key requirement

    We must find the minimum number of platforms so that all trains can be accommodated without delay.
  3. Final Answer:

    The least number of platforms needed so no train waits -> Option D
  4. Quick Check:

    Minimum platforms = no waiting trains [OK]
Hint: Count overlapping trains to find minimum platforms needed [OK]
Common Mistakes:
  • Confusing total trains with platforms needed
  • Ignoring overlapping arrival and departure times
  • Thinking about train durations instead of platform count
2. Which Go code snippet correctly declares slices for arrival and departure times for the Minimum Number of Platforms problem?
easy
A. arrivals := [900, 940, 950]; departures := [910, 1200, 1120]
B. arrivals := []int{900, 940, 950}; departures := []int{910, 1200, 1120}
C. arrivals := (900, 940, 950); departures := (910, 1200, 1120)
D. arrivals := {900, 940, 950}; departures := {910, 1200, 1120}

Solution

  1. Step 1: Recall Go slice syntax

    In Go, slices are declared with []int{values}, not with parentheses or braces alone.
  2. Step 2: Match correct syntax

    arrivals := []int{900, 940, 950}; departures := []int{910, 1200, 1120} uses []int{...} which is correct; others use invalid syntax.
  3. Final Answer:

    arrivals := []int{900, 940, 950}; departures := []int{910, 1200, 1120} -> Option B
  4. Quick Check:

    Go slices use []int{...} [OK]
Hint: Use []int{...} to declare slices in Go [OK]
Common Mistakes:
  • Using parentheses () instead of braces {}
  • Using braces {} without []int type
  • Confusing arrays and slices syntax
3. What is the minimum number of platforms required for trains with arrival times [900, 940, 950, 1100, 1500, 1800] and departure times [910, 1200, 1120, 1130, 1900, 2000]?
medium
A. 3
B. 2
C. 4
D. 1

Solution

  1. Step 1: Sort arrival and departure times

    Arrivals: 900, 940, 950, 1100, 1500, 1800; Departures: 910, 1120, 1130, 1200, 1900, 2000.
  2. Step 2: Count overlapping trains

    Between 940 and 1120, three trains overlap (940, 950, 1100 arrivals with departures after 940). So minimum platforms = 3.
  3. Final Answer:

    3 -> Option A
  4. Quick Check:

    Max overlap = 3 trains [OK]
Hint: Sort times and count overlaps to find max platforms [OK]
Common Mistakes:
  • Not sorting times before counting
  • Counting total trains instead of overlaps
  • Mixing arrival and departure times
4. Given this Go code snippet for Minimum Number of Platforms, what is the bug?
arrivals := []int{900, 940, 950}
departures := []int{910, 1200, 1120}
i, j, platforms := 0, 0, 0
for i < len(arrivals) && j < len(departures) {
  if arrivals[i] <= departures[j] {
    platforms++
    i++
  } else {
    platforms--
    j++
  }
}
fmt.Println(platforms)
medium
A. platforms should not be decremented when a train departs
B. The loop should run until i < len(arrivals) only
C. The comparison should be arrivals[i] < departures[j], not <=
D. platforms variable should be initialized to 1

Solution

  1. Step 1: Understand platform counting logic

    When arrival time equals departure time, we should consider the train has left before the next arrives to avoid extra platform count.
  2. Step 2: Fix comparison operator

    Using <= causes increment even when arrival equals departure, inflating platform count. Changing to < fixes this.
  3. Final Answer:

    The comparison should be arrivals[i] < departures[j], not <= -> Option C
  4. Quick Check:

    Use < to avoid counting simultaneous arrival/departure as overlap [OK]
Hint: Use strict less than (<) to avoid counting equal times as overlap [OK]
Common Mistakes:
  • Using <= instead of < in time comparison
  • Incorrect loop termination conditions
  • Wrong initialization of platform count
5. You have arrival times [900, 940, 950, 1100, 1500, 1800] and departure times [910, 1200, 1120, 1130, 1900, 2000]. How would you modify the algorithm to also return the time intervals when the maximum number of platforms are needed?
hard
A. Track intervals when platform count reaches max during iteration
B. Sort only arrival times and print max arrival time intervals
C. Count total trains and divide by 2 to get intervals
D. Use a queue to store trains and print all arrival times

Solution

  1. Step 1: Track platform count and max count during iteration

    While iterating sorted arrivals and departures, keep updating current platform count and record when it reaches a new maximum.
  2. Step 2: Record time intervals for max platforms

    Store the start time when max platforms count is reached and end time when it decreases, to get intervals.
  3. Final Answer:

    Track intervals when platform count reaches max during iteration -> Option A
  4. Quick Check:

    Record max platform count intervals while counting platforms [OK]
Hint: Save start/end times when platform count hits max [OK]
Common Mistakes:
  • Ignoring departure times when tracking intervals
  • Only sorting arrivals without departures
  • Using total trains count instead of overlaps
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard