Uber| Phonescreen | SSE

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2022-02-03Added By Anonymous
Source: Link

Company: Uber
Role: Senior Software Engineer
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

Given a grid G of numbers representing heights of persons standing.

- A person can see another person in the grid if the height of everyone in between is shorter than them
- A person can see to the right and down
Return a grid A where A[x][y] is the sum of all the persons seen from G[x][y]

Example
[9, 6, 8, 5, 11]
[1, 5, 3, 7, 9]
[2, 1, 4, 6, 1]


Output
[5, 3, 4, 2, 1]
[4, 4, 3, 2, 1]
[3, 2, 1, 1, 0]

For example:
{2,0}-2, can see {1,4,6}. 2 can see 1 because its very next(note: 2 can see any number next to it} ,4 can be seen because 1 cant hide a person whose height is 4 and 4 cant hide a person whose height is 6.

Comments