FastPrepLift Total Travel
Problems/Lift Total Travel

Lift Total Travel

Infosys logoInfosys● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported from an Infosys online assessment for the Specialist Programmer and Digital Specialist Engineer roles in November 2026. A lift answers floor calls one after another from a starting floor, calls to floors under maintenance are dropped without moving, and you return how many floors it travels in total.

The report gave this task, the input layout (the number of calls, one row per call with a floor and a 1 or 0 for working or closed, then the starting floor) and three examples with answers. It gave no limits. We chose the limits (up to 10^4 calls, floors from 0 to 10^9), so the total can pass the 32-bit range and the answer is returned as a 64-bit integer. The calls and the starting floor are passed to a function instead of being read line by line.

Our version is about 95% the same as the reported question.

A lift starts on floor s and receives n calls in order. Each call is given as calls[i] = [floor, open]: the call asks the lift to go to floor floor, and open tells whether that floor is working (1) or closed for maintenance (0).

The lift serves the calls strictly in the given order:

  • For a call to a working floor, the lift travels straight from its current floor to the called floor. Each floor it passes costs one unit of travel, so going from floor a to floor b costs |a - b|.
  • A call to a closed floor is cancelled. The lift ignores it completely and stays where it is.

Return the total travel of the lift over all the calls.

Function

totalTravel(calls: int[][], s: int) → long

Examples

Example 1

calls = [[3,1],[7,1],[2,1]]s = 1return = 11

Every floor is working. The lift goes from floor 1 to 3 (2 floors), then from 3 to 7 (4 floors), then from 7 to 2 (5 floors). The total is 2 + 4 + 5 = 11.

Example 2

calls = [[3,1],[7,0],[2,1]]s = 1return = 3

The lift goes from floor 1 to 3 (2 floors). Floor 7 is closed, so that call is cancelled and the lift stays on floor 3. Then it goes from 3 to 2 (1 floor). The total is 2 + 1 = 3.

Example 3

calls = [[3,0],[7,0],[2,0]]s = 1return = 0

Every called floor is closed, so all three calls are cancelled and the lift never leaves floor 1. The total is 0.

Constraints

  • 1 <= calls.length <= 10^4
  • calls[i].length == 2
  • 0 <= calls[i][j] <= 10^9
  • calls[i][1] is 0 or 1
  • 0 <= s <= 10^9

More Infosys Online Assessment questions

  • Hiking Club Fastest PaceOA · Seen Nov 2026
  • Lowest Common Ancestor with a Changing RootOA · Seen Nov 2026
  • Minimum Leaf Path Sum over All RootsOA · Seen Nov 2026
  • Split Array to Minimize the Largest SumOA · Seen Nov 2026
  • Cherry PickupOA · Seen Nov 2026
  • Lexicographically Smallest Grid Path with One Letter ChangeOA · Seen Nov 2026
  • Minimum Cost to Supply Water with Wells and PipesOA · Seen Nov 2026
  • Minimum Cost to Tile a Strip with Widths 1, 2, and 3OA · Seen Nov 2026
  • Minimum Rounds to Complete All TasksOA · Seen Nov 2026
  • Count Equal-Distinct Character PartitionsOA · Seen Oct 2026

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OA
  • Book Reading EveningsGoogle · OA
  • Basic Item DiscountsPalantir · OA
  • Wind-Blown Leaves Remaining in a GridAbridge · OA
  • Shell Command Counts with History ReferencesTikTok · OA
  • Count Dropped RequestsJP Morgan Chase · OA
  • Recursively Expanded Shell Command CountsHudson River Trading · OA
  • Diagonal Bounce TraversalAutodesk · OA
  • First Value Below Both NeighborsCapital One · OA
  • REST API: Highest International StudentsRippling · OA
See Infosys hiring insights
Saved
class Solution {
    public long totalTravel(int[][] calls, int s) {
        // Write your code here.
    }
}
Checking account…