Skip to main content
All Questions

Compute the total travel of a lift that serves calls in order.

Unlock detailed company stats for this questionUpgrade

A lift starts on floor S and receives N calls in order, each asking for floor f[i]. It serves calls strictly in order, travelling straight from its current floor to the one called at one unit of travel per floor. Calls to floors closed for maintenance are cancelled: the lift ignores them completely and stays where it is. Return the total travel over the shift.

Input: N, then N rows of (floor, working) where 1 means the floor is working and 0 means under maintenance, then S. Calls to closed floors are cancelled and the lift stays where it is. Example 1: N=3, calls (3,1) (7,1) (2,1), S=1 -> 11 Example 2: N=3, calls (3,1) (7,0) (2,1), S=1 -> 3 Example 3: N=3, calls (3,0) (7,0) (2,0), S=1 -> 0

Format · Online coding test on the Wingspan platform, in Java.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.