Data Structures & AlgorithmsHardGATE CS · TCS NQT
Arrivals at times 1, 2, 3, 5 and departures at 2, 4, 5, 6 (each arrival pairs with a departure; a train leaving at time t frees its platform for one arriving at time t). What is the minimum number of platforms?
- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
Sweep events in time order with departures processed before arrivals at equal times. Processing arrivals first at ties over-counts platforms here.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Take the XOR of a[i] XOR a[j] over all pairs i < j in [1, 2, 3, 4]. How many set bits (1-bits) does this combined XOR have?
- How many index triples i < j < k in [1, 2, 3, 4, 5, 6] satisfy a[i] + a[j] = a[k]?
- What is the smallest positive integer k such that k! is divisible by 2^10 = 1024?
- What is the length of the longest contiguous subarray of [2, 3, 1, 2, 4, 3] whose sum is exactly 7?
- The array [5, 3, 8, 6, 2] must be split into exactly 2 contiguous groups, minimising the largest group sum. What is that minimum?
- Evaluate "2 3 # 4 #" where the binary operator # on operands a and b (in postfix order) returns a b + 1.