Arnab Chakraborty has Published 4293 Articles

Check for Majority Element in a sorted array in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 14:18:48

192 Views

Suppose we have an array; we have to check whether given number x is the majority element of that array or not. The array is sorted. One element is said to be majority element, when it appears n/2 times in the array. Suppose an array is like {1, 2, 3, ... Read More

Check for Identical BSTs without building the trees in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 14:17:00

150 Views

We have two arrays to represent the elements of the BST. If we take elements from that array from left to right, and form the BST, then by taking from both the arrays, we will make the same BST. We have to check whether both are forming the same or ... Read More

Check for Children Sum Property in a Binary Tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 14:12:36

140 Views

Suppose we have a binary tree. The binary tree is valid when it meets the following property.Each node should contain data value same as the sum of left and right children values. If there are no children at any side, then it will be treated as 0.Suppose a tree is ... Read More

Check for balanced parentheses in an expression in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 14:09:19

4K+ Views

Suppose we have an expression. The expression has some parentheses; we have to check the parentheses are balanced or not. The order of the parentheses are (), {} and []. Suppose there are two strings. “()[(){()}]” this is valid, but “{[}]” is invalid.The task is simple; we will use stack ... Read More

Check for an array element that is coprime with all others in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 14:03:30

332 Views

Suppose we have an array A[] of positive integers, where 2

Floor and Ceil from a BST in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 13:56:29

281 Views

Here we will see, how to find the Floor and Ceiling value from BST. For example, if we want to make a memory management system, where free nodes are arranged in BST. Find best fit for the input request. Suppose we are moving down the tree with smallest data larger ... Read More

Finding LCM of more than two (or array) numbers without using GCD in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 13:52:20

1K+ Views

We have an array A, we have to find the LCM of all elements without using the GCD operation. If the array is like {4, 6, 12, 24, 30}, then the LCM will be 120.The LCM can be calculated easily for two numbers. We have to follow this algorithm to ... Read More

Finding a Non Transitive Coprime Triplet in a Range in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 13:49:21

140 Views

Suppose we have the lower and upper bound, and we have to find nontransitive triplet (x, y, z), such that the pair (x, y) are coprime (GCD is 1), the pair (y, z) are coprime, but pair (x, z) is not a coprime pair. For example, if the lower bound ... Read More

Find the Rotation Count in Rotated Sorted array in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 13:47:00

270 Views

Consider we have an array, which is rotated sorted array. We have to find number of rotations are required to sort the array. (We will consider rotation right to left.)Suppose the array is like: {15, 17, 1, 2, 6, 11}, then we have to rotate the array two times to ... Read More

Find the GCD of N Fibonacci Numbers with given Indices in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 21-Oct-2019 13:42:27

224 Views

Here we have to find the GCD of n Fibonacci terms with the given indices. So at first we have to get the maximum index, and generate Fibonacci terms, some Fibonacci terms are like this: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ….. The index is starts ... Read More

Advertisements