Arnab Chakraborty has Published 4452 Articles

Program to find nth smallest number from a given matrix in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 20-Nov-2020 05:47:00

119 Views

Suppose we have a 2D matrix, where each row and column is sorted in non-decreasing order, we have to find the nth smallest number.So, if the input is like243034316632And n = 4, then the output will be 6.To solve this, we will follow these steps −lst := a new listfor ... Read More

Program to generate matrix where each cell holds Manhattan distance from nearest 0 in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 20-Nov-2020 05:45:39

179 Views

Suppose we have a binary matrix. We have to find the same matrix, but each cell's value will be the Manhattan distance to the nearest 0. We can assume at least one 0 exists in the matrix.So, if the input is like101101110then the output will be101101210as only the bottom left ... Read More

Program to find number of combinations of coins to reach target in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 20-Nov-2020 05:43:36

1K+ Views

Suppose we have a list of coins and another value amount, we have to find the number of combinations there are that sum to amount. If the answer is very large, then mod the result by 10^9 + 7.So, if the input is like coins = [2, 5] amount = ... Read More

Program to find lowest sum of pairs greater than given target in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 20-Nov-2020 05:40:22

185 Views

Suppose we have a list of numbers called nums and another value target. We have to find the lowest sum of pair of numbers that is larger than target.So, if the input is like nums = [2, 4, 6, 10, 14] target = 10, then the output will be 12, ... Read More

Lonely Pixel I in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 10:17:47

155 Views

Suppose we have a picture consisting of black and white pixels, we have to find the number of black lonely pixels. Here the picture is represented by a 2D char array consisting of 'B' and 'W', for the black and white pixels respectively.A black lonely pixel is actually 'B' that ... Read More

Inorder Successor in BST II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 10:15:29

304 Views

Suppose we have a node in a binary search tree, we have to find the in-order successor of that node in the BST. If there is no in-order successor, return null. As we know that the successor of a node is the node with the smallest key greater than value ... Read More

The Maze II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 10:13:27

429 Views

Suppose there is a ball in a maze with empty spaces and walls. Now the ball can go through empty paths by rolling any direction like up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.We ... Read More

The Maze in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 10:05:40

3K+ Views

Suppose there is a ball in a maze with empty spaces and walls. Now the ball can go through empty paths by rolling any direction like up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.We ... Read More

Max Consecutive Ones II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 10:00:51

1K+ Views

Suppose we have a binary array; we have to find the maximum number of consecutive 1s in this array if we can flip at most one 0.So, if the input is like [1, 0, 1, 1, 0], then the output will be 4 because if we flip the first zero ... Read More

Find Permutation in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 09:58:36

250 Views

Suppose we have a secret signature consisting of character 'D' and 'I'. 'D' denotes the decreasing relationship between two numbers, 'I' denotes increasing relationship between two numbers. And the secret signature was constructed by a special integer array, which contains uniquely all the different number from 1 to n.For example, ... Read More

Advertisements