Arnab Chakraborty has Published 4293 Articles

Maximum Product of Three Numbers in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Jun-2020 12:04:32

800 Views

Suppose we have an integer array; we have to find three numbers whose product is maximum then return the maximum product.So, if the input is like [1, 1, 2, 3, 3], then the output will be 18, as the three elements are [2, 3, 3].To solve this, we will follow ... Read More

Can Place Flowers in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Jun-2020 12:03:16

1K+ Views

Suppose we have a long flowerbed in which some of the plots are planted and some are empty. Now there is a constraint, flowers cannot be planted in adjacent plots, they would compete for water and both would die. So if we have a flowerbed, represented by an array containing ... Read More

Minimum Index Sum of Two Lists in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Jun-2020 12:00:29

194 Views

Suppose there are two fiends Amal and Bimal want to choose a restaurant for dinner, now they both have a list of favorite restaurants represented by strings. We have to help them to find out their common interest with the least list index sum. If there is a choice tie ... Read More

Range Addition II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Jun-2020 11:59:08

218 Views

Suppose we have one m * n matrix called M and this is initialized with all 0's and we also have several update operations. Now, operations are represented by a 2D array, and each operation is represented by an array with two positive integers x and y, it means M[i][j] ... Read More

Longest Harmonious Subsequence in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Jun-2020 11:56:24

511 Views

Suppose we have an integer array; we have to find the length of its longest harmonious subsequence among all its possible subsequences. As we know a harmonious sequence array is an array where the difference between its maximum value and its minimum value is exactly 1.So, if the input is ... Read More

N-ary Tree Preorder Traversal in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Jun-2020 11:54:51

641 Views

Suppose we have one n-ary tree, we have to find the preorder traversal of its nodes.So, if the input is likethen the output will be [1, 3, 5, 6, 2, 4]To solve this, we will follow these steps −Define an array ansDefine a method called preorder(), this will take rootif ... Read More

Distribute Candies in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Jun-2020 11:53:30

294 Views

Suppose we have an array with even length, here different numbers in this array will represent different kinds of candies. Now each number means one candy of the corresponding kind. we have to distribute candies equally in number to brother and sister. We have to find the maximum number of ... Read More

Reshape the Matrix in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 11-Jun-2020 11:52:00

2K+ Views

In different platform there is very useful function called 'reshape', that function is used to reshape a matrix into a new one with different size but data will be same. So, if we have a matrix and two values r and c for the row number and column number of ... Read More

Convert BST to Greater Tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Jun-2020 13:09:58

172 Views

Suppose we have a Binary Search Tree, we have to convert it into a Greater Tree such that every key of the original BST is changed to the original key + sum of all keys greater than the original key in BST.So, if the input is likethen the output will ... Read More

K-diff Pairs in an Array in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Jun-2020 13:06:16

353 Views

Suppose we have an array and an integer k, we have to find the number of unique k-diff pairs in the array. Here the k-diff pair is like (i, j), where i and j are both are present in the array and their absolute difference is k.So, if the input ... Read More

Advertisements