Given a binary tree, print the level order traversal of its node’s values.
For example:
Given below binary tree, the level order traversal of this binary tree is 7, 6, 5, 4, 3, 2, 1.
Given a binary tree, print the level order traversal of its node’s values.
For example:
Given below binary tree, the level order traversal of this binary tree is 7, 6, 5, 4, 3, 2, 1.
Single Element in a Sorted Array. Find the element that appears once in a sorted array where every other element appears twice.
Given a sorted array of integers. In this array, every element appears twice except one element which appears only once. Write a code to find the element which appears only once.
For example:
Example 1:
Input: [1, 1, 2, 2, 3, 4, 4, 7, 7]
Output: 3
Except 3 every other element appears twice.
Example 2:
Input: [1, 1, 2, 2, 3, 3, 4, 5, 5]
Output: 4
NOTE – Try to solve this problem in O(logn) time complexity and by using constant space O(1).
Given an array of integers, find Maximum difference between two elements such that larger number appears after the smaller number. In this tutorial, I am going to discuss multiple approaches and their java code to find maximum difference between two elements.
For example :
Example 1:
arr = {2, 5, 15, 6, 4}
Output: 13
The difference between 15 and 2 is 13. Element 15 is greater than 2 and it satisfies our condition that larger number appears after the smaller number.
Example 2:
arr = {7, 9, 5, 6, 13, 2};
Output : 8
The difference between 13 and 5 is 8 (13-5).