Walmart | First Round | India

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2022-06-24Added By Anonymous
Source: Link

Suppose you are given n number of people, all having different heights. The task is to arrange n people in a single line such that exactly x of them are visible from left and y of them visible from right (Since some taller people block the view of the shorter ones).


For example, if the people were arranged in line with heights 30 cm, 10 cm, 50 cm, 40 cm, and then 20 cm, someone looking from the left side would see 2 persons (30 and 50 cm) while someone looking from the right side would see 3 persons (20, 40 and 50 cm).

Comments