Find Floor of an element in a Sorted Array
Question: You are given an array and a key. You need to return the floor of that element. What is floor? If you are given a number say “5.8”, the floor of that number is 5 and ceil is 6. What will be...
View ArticleFind Ceil of an element in a Sorted Array
Question: You are given an array and a key. You need to return the Ceil of that element. What is Ceil? If you are given a number say “5.8”, the floor of that number is 5 and ceil is 6. What will be the...
View ArticleFind position of an element in an Infinite Sorted Array
Question: You are given an array in sorted order, but it is infinite. You are also given an key element. You need to check if the element is present in that infinite array. array = {1, 2, 3, 4, 5, 7,...
View ArticleFind the index of first 1 in an infinite sorted array of 0s and 1s
Problem statement: You are given a sorted array of infinite length of 0’s and 1’s. You need to find the first occurrence of 1. Example: array = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}...
View ArticlePeak Element
Problem Statement: You are given an unsorted array and you need to send the index of peak element. Understanding what is Peak element? 1. An element who is greater than both of its neighbor. Example...
View ArticleFind maximum element in Bitonic Array
Problem statement: Given an bitonic array, find the max element in that. Example: Array {1, 2, 3, 4, 5, 4, 3, 2, 1}; Output = 5 A bitonic array is an ascending sorted array where, after a particular...
View ArticleSearch An Element in Bitonic Array
Problem statement: Given an bitonic array, find the max element in that. Example: Array {1, 2, 3, 4, 5, 4, 3, 2, 1}; key = 1 Output = 0 or 9 A bitonic array is an ascending sorted array where, after a...
View ArticleGet the rotation count in sorted rotated array
Problem Statement: You are given an array, you need to check if the array is sorted and rotated. Example: array = {6, 7, 1, 2, 3, 4, 5} Output; True array = {1, 2, 3, 4, 5} Output; False Because it is...
View ArticleCount the number of 1’s in an array sorted in decreasing order.
Question: You are given an array that is sorted in decreasing order and has only 0’s and 1’s. You need to find the number of 1’s present in it. Example: array = {1,1,1,1,1,0,0,0} Output = 5 array =...
View ArticlePower of 2
Given a number, you need to check if the number is a power of 2, return true or false accordingly. Example: Input: 1 Output: True Because 2^0 is 1 Input: 15 Output: False Because 15 is not a power of...
View ArticleMissing Number
Problem statement: You are given an array of numbers from 1 to n, in any order, one number will be missing. You need to find a missing number. Example: Input: [0, 1, 3] Output: 2 We can solve this...
View ArticleCounting set bits in a number
You are given a number; you need to create an array to fill the number of 1’s present in their binary format. Example: Input n = 3 Output = [0, 1, 1, 2] Because for 0, the number of set bits is 0. For...
View ArticleHamming Distance
You are given 2 integers, and you need to return the count at which the bits are different in their binary form. Consider 8 and 1 As highlighted in the image, there are 2 positions where the bits are...
View ArticleBitwise and of number range
You are given a number range, you need to find the bitwise and of all the numbers in the range. Example: [5, 7] The bitwise and of 5, 6, 7 will be 4. The solution is very simple, once you understand...
View ArticleBottom view of binary Tree
In this tutorial, we shall solve how to print bottom view of a binary tree. Problem statement: You are given a binary tree; you need to print the bottom view of a binary tree. Consider the tree: So the...
View ArticleBoundary Traversal of Binary Tree
We shall solve boundary traversal of binary tree in this tutorial. Problem Statement: Given a binary tree, list all the nodes that come in the boundary. Consider the tree as below: So the boundary...
View ArticleTop view of a binary tree
In this chapter we shall learn how to print top view of a binary tree. Problem Statement: You are given a root node of the tree print the top view of the tree. For example: Consider the below tree: So...
View ArticleLeft view and right view of a Binary Tree
Problem Statement: Given a binary tree, print the left and right view of the tree. For example: If you have a tree as below: The left view will be a, b, d, h and right view will be a, c, g, j. As...
View ArticleLevel Order Traversal
In this tutorial we shall see how to print level by level of the tree nodes. Problem Statement: Given the root node of the tree, print the nodes level by level. For example: Consider the tree below:...
View ArticleCheck if 2 binary tree are identical
In this chapter, we shall see if 2 trees are identical. Problem statement: You are given root node of 2 binary trees, you need to check if 2 trees are identical. Example: Consider the below image The...
View Article