This is a verified interview question from Bny. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Climbing Up and Down" covers key patterns like Graphs.
"### Problem There is a newly constructed building in New York city with N floors. There are M elevators available in the building, each of which connects two specific floors. Unfortunately, each elevator is not accessible on all the floors, meaning the elevators do not make any stops between the two specified floors. You are given two arrays representing the starting and the ending floors of each elevator respectively. Using the elevators, you want to reach the highest floor you can in the building. Your task is to find and return the highest floor you can reach using the elevators. ### Note - The elevator can move in either direction, from floor A to floor B or vice versa. - Initially you are on the ground floor marked as 1. ### Input Specification: - Input 1: An integer value N, representing the total number of floors in the building. - Input 2: An integer value M, representing the number of elevators. - Input 3: An integer array representing the starting points of each elevator. - Input 4: An integer array representing the ending points of each elevator. ### Output Specification: Return an integer value representing the highest floor you can reach by using M elevators."
Join thousands of developers practicing for Bny.