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?

  1. A. 4
  2. B. 12
  3. C. 5
  4. 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

Exams that ask this topic