Arnab Chakraborty has Published 4293 Articles

Guess Number Higher or Lower II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 14:25:59

309 Views

Suppose we are playing the Guess Game. The rules of the game is as follows −Player1 pick a number from 1 to n. player2 have to guess which number is picked by player1.Every time player2 guess wrong, player1 will tell whether the number that is picked is higher or lower.However, ... Read More

Convert Sorted List to Binary Search Tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 14:16:42

192 Views

Suppose we have a singly linked list where elements are sorted in ascending order, we have to convert it to a height balanced BST. So if the list is like [-10, -3, 0, 5, 9], The possible tree will be like −To solve this, we will follow these steps −If ... Read More

Find K Pairs with Smallest Sums in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 14:15:57

203 Views

Suppose we have two sorted arrays A1 and A2, and another value k. We have to define a pair (u, v) which is consists of one element from A1 and another element from A2. We have to find the k pairs like [(u1, v1), (u2, v2), …, (uk, vk)]. So ... Read More

Populating Next Right Pointers in Each Node in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 14:10:34

277 Views

Suppose we have a complete binary tree, where each node has following fields: (data, left, right, next), the left will point to left subtree, right will point to right subtree, and the next pointer will point to the next node. If there is no node in the right hand side, ... Read More

Sort Integers by The Power Value in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 14:08:54

245 Views

As we know that the power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps −if x is even then x = x / 2if x is odd then x = 3 * x + 1So for example, ... Read More

Populating Next Right Pointers in Each Node II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 14:04:39

142 Views

Suppose we have a binary tree, where each node has following fields: (data, left, right, next), the left will point to left subtree, right will point to right subtree, and the next pointer will point to the next node. If there is no node in the right hand side, then ... Read More

Design a Stack With Increment Operation in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 13:51:06

663 Views

Suppose we want to design a stack that supports the following operations.CustomStack(int maxSize) This initializes the object with maxSize which is the maximum number of elements in the stack or do nothing if the stack reached the maxSize.void push(int x) This inserts x to the top of the stack if ... Read More

Find a Corresponding Node of a Binary Tree in a Clone of That Tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 13:44:49

639 Views

Suppose we have two binary trees original and cloned and given a reference to a node target in the original tree. The cloned tree is actually a copy of the original tree. We have to find a reference to the same node in the cloned tree.So if the tree is ... Read More

Time Needed to Inform All Employees in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 13:37:56

454 Views

Suppose we have a company has n employees with a unique ID for each employee. These IDs are ranging from 0 to n - 1. The head of the company has is the one with headID. Each employee has one direct manager given in the manager array where manager[i] is ... Read More

Bulb Switcher III in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 13:21:40

435 Views

Suppose we have a room with n bulbs, these are numbered from 1 to n, arranged in a row from left to right. Initially, all the bulbs are turned off. At moment k (for k in range 0 to n - 1), we turn on the light[k] bulb. A bulb ... Read More

Advertisements