Round 1
Questions: You are given a pyramid of blocks with total_levels levels. The pyramid is structured such that:
The topmost level contains 1 block.
The second level contains 3 blocks.
The third level contains 5 blocks.
and so on ...
For example, a pyramid with 4 levels appears like this:
______ | | ______ ______ ______ | || || | ______ ______ ______ ______ ______ | || || || || | ______ ______ ______ ______ ______ ______ ______ | || || || || || || |
Initially, distinct integers from 1 to 2 * total_levels - 1 are written into the blocks of the bottom-most level. All higher levels are filled according to the following rule:
The value of each block at any higher level must be the median of the three blocks directly below it (the block directly beneath it, the block to the left, and the block to the right).
Determine the number written in the block at the topmost level of the pyramid.
Example:
______ | | ______ ______ ______ | || || | ______ ______ ______ ______ ______ | || || || || | ______ ______ ______ ______ ______ ______ ______ | 1 || 6 || 3 || 7 || 4 || 5 || 2 |
Return value: 4 because:
______ | 4 | ______ ______ ______ | 4 || 5 || 4 | ______ ______ ______ ______ ______ | 3 || 6 || 4 || 5 || 4 | ______ ______ ______ ______ ______ ______ ______ | 1 || 6 || 3 || 7 || 4 || 5 || 2 |
Function find_top_block(bottom_level):
Examples:
- For input
1 2 3
, return value: 2 - For input
1 2 3 6 5 4 7
, return value: 5 - For input
7 3 6 2 4 5 1
, return value: 2 - For input
1 6 2 7 4 5 3
, return value: 4 - For input
[16, 3, 2, 7, 4, 5, 10, 8, 9, 11, 12, 13, 1]
, return value: 8 - For input
[8, 4, 1, 9, 5, 7, 3, 6, 2]
, return value: 5 - For input
[2, 4, 3, 5, 9, 7, 6, 8, 1]
, return value: 7
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.