Uber | SDE 2 Interview | Hard Question

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-03-30Added By Anonymous
Source: Link

Company: Uber

Role: software engineer ii

Interview Stage: Onsite


Original Post Content:


I recently got a chance to interview with Uber for SDE 2 role.

I faced an interesting and challenging question in Virtual Onsite round 1.


[QuadTree Compression of a Matrix]


Problem Statement


A QuadTree is a tree data structure in which each internal node is either a leaf node or has exactly four children. QuadTrees are often used to partition a two-dimensional space by recursively subdividing it into four quadrants or regions.


Given an n x n matrix of integers, compress it using a QuadTree. A region can be compressed into a single value if all elements in that region are the same.


Example


Input:


|2 | 2 |3 |3|

|2 | 2 |3 |3|

|4 | 2 |5 |5|

|2 | 3 |5 |5|


Output:


| | |

| 2 | 3 |

| | |

| 4 | 2 | 5 |

| 2 | 3 | |


IMG_9212.jpeg


I gave a recursive approach, using a QuadTree data structure, but the interviewer didn't seem impressed.

I got a rejection mail after a day.

Please feel free to post your solution in comments.

Comments