Company: Flipkart

Difficulty: easy

Problem Statement

Last Node of Every Complete Level An almost complete binary tree is stored in the usual level-order array layout: position 1 holds the root, and the children of position i are at positions 2 i and 2 i + 1 . The tree has n nodes, occupying positions 1 through n with no gaps, so every level is filled from left to right and only the deepest level may be short. Number the levels from 0 . Level k occupies positions 2^k through 2^(k+1) - 1 , so a complete level k holds exactly 2^k nodes. A level is complete if every one of its 2^k positions is present in the tree, i.e. if 2^(k+1) - 1 <= n . Report the value stored at the last (right-most) node of every complete level, ordered from the shallowest level to the deepest one. Levels that are not complete are skipped entirely. Input Format The first line contains one integer n , the number of nodes. The second line contains n space-separated integers, the node values in level order (position 1 first). Output Format A single line with the requir

More Flipkart OA questionsInterview experiences