Reverse Level Order Traversal of a Binary Tree

Given a binary tree, write a code to print its reverse level order traversal.

For example:

The reverse or bottom-up level order traversal of this binary tree is 4, 3, 2, 1, 6, 5, 7.

In this example, first we printed last level then second last level and so on. So, we have to start printing the level from bottom-up.

Maximum Consecutive Ones II

Maximum consecutive ones II. Given an array which only consists of 0s and 1s. Write a code to find the maximum number of consecutive 1s in an array, if you can flip at most one 0.

For example:

Input: {1, 1, 0, 0, 1, 1, 1, 1, 1}

Output: 6

In this example, If we can flip at most one zero then the maximum number of consecutive 1s in an array is 6 {1, 1, 1, 1, 1, 1}.

Group Anagrams Together

Given an array of strings or a list of words, write a code to group anagrams together.

what are Anagrams?

Two strings are said to be anagrams of each other if it contains the same characters, only the order of character in both the strings is different.

Check whether two strings are anagrams of each other or not

For example, Word “car” and “rac” are anagrams of each other. As both, the strings contain the same number of characters only the order of character is different in both the strings.

Now, let’s understand this problem statement with example.

For example:

Input: {“eat”, “tea”, “tan”, “ate”, “nat”, “bat”}

Output: