Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Elevator starts at floor 0. Requests arrive in order for floors 3, 1, 4 (the elevator serves each request by going directly to that floor, one request at a time). What is the total number of floors travelled?
- A. 4
- B. 12
- C. 5
- D. 8
Correct answer: D. 8
Serving requests in arrival order: 0 → 3 (3), 3 → 1 (2), 1 → 4 (3), total 8. Sorting the requests like a SCAN sweep (0 → 1 → 3 → 4) gives 4, adding a return trip to floor 0 gives 12, and forgetting the first leg from floor 0 gives 5.
More Coding Interview Problems questions
- Problem: A traffic light cycles green for 30 s, then yellow for 5 s, then red for 25 s, starting at time 0 with green. How many whole…
- Problem: A water-jug problem: a 3-litre jug and a 5-litre jug, both empty, and unlimited water. Allowed actions: fill a jug fully, empty a…
- Problem: The string "PAYPALISHIRING" is written in a zigzag on 3 rows (letters go down the rows in a zigzag, then the rows are read left…
- Problem: How many ordered pairs (i, j) with 1 ≤ i < j ≤ 10 satisfy i XOR j = 3?
- Problem: In how many ways can 100 be written as a sum of two perfect squares x² + y² with 0 ≤ x ≤ y (unordered, non-negative)?
- Problem: How many prime numbers are there in the range 1 to 200 (inclusive)?