Print a Binary tree in level order with new line after every level

Problem Given a binary tree, you have to print level order traversal of the tree (left child then right child) but every next level has to be printed in next line. Example If the given tree is 5 10 15 56 47 12 42 ```Then the output should be 5 10 15 56 47 12 42 ### Solution Here is the approach: 1. Start with a root node. Add it to a new list. [Read More]

Given an array filled with char elements, find the max length of continuous white space

Problem Given array filled with char elements, can you suggest a most efficient way to find the max length of continuous white space? Solution Scan the array left to right, keep a count of white space. When you reach a non-whitespace character, check that count against the current max; if it’s higher, it becomes the new max. Set the count back to zero, continue scanning. Time complexity - O(n) [Read More]

Find the longest oscillating subsequence

Given the sequence of numbers find the longest oscillating subsequence Solution The oscillating sequence is the sequence, when the 2 adjacent numbers are either greater than or smaller than the current number. So, for example following is the oscillating sequence: 1, 7, 4, 6, 2 So, 7 is greater than both 1 and 4, 4 is less than both 4 and 6 and so on. Now, given the sequence of number we have to find the longest oscillating subsequence. [Read More]