Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 180 of 377

Combination Sum II in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 540 Views

Suppose we have a set of candidate numbers (all elements are unique) and a target number. We have to find all unique combinations in candidates where the candidate numbers sum to the given target. The same number will not be chosen from candidates more than once. So if the elements are [2, 3, 6, 7, 8] and the target value is 8, then the possible output will be [[2, 6], [8]]Let us see the steps −We will solve this in recursive manner. The recursive function is named as solve(). This takes index, an array a, the integer b and another ...

Read More

Jump Game in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 3K+ Views

Suppose we have an array of non-negative integers; we are initially positioned at the first index of the array. Each element in the given array represents out maximum jump length at that position. We have to determine if we are able to reach the last index or not. So if the array is like [2, 3, 1, 1, 4], then the output will be true. This is like jump one step from position 0 to 1, then three step from position 1 to the end.Let us see the steps −n := length of array A – 1for i := n ...

Read More

Merge Intervals in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have a collection of intervals, we have to merge all overlapping intervals. So if the intervals are like [[1, 3], [2, 6], [8, 10], [15, 18]], then the intervals after merging will be [[1, 6], [8, 10], [15, 18]]. This is because there were two intervals those are overlapping, the intervals are [1, 3] and [2, 6], these are merged to [1, 6]Let us see the steps −if interval list length is 0, then return a blank listsort the interval list using quicksort mechanismstack := an empty stack, and insert intervals[0] into the stackfor i in range 1 ...

Read More

Spiral Matrix II in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have a positive integer n, we have to generate a square matrix with n2 elements in spiral order. So if n = 5, then the matrix will be −12341213145111615610987Let us see the steps −set (row1, col1) := (0, 0) and (row2, col2) := (n, n), and create one matrix called res, then fill it with 0s, and set num := 1while num n2, then breakfor i in range row1 + 1 to row2, res[i, col2-1] = num, incase num by 1if num > n2, then breakfor i in range col2 – 2 down to col1 – 1, ...

Read More

Unique Paths in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 808 Views

Suppose there is a robot is located at the top-left corner of a n x m grid (n rows and m columns). The robot can only move either down side or right side at any point in time. The robot wants to reach the bottom-right corner of the grid (marked 'END in the diagram below). So we have to find how many possible unique paths are there? For example if m = 3 and n = 2, then the grid will be like below −RoboENDThe output will be 3, So there are total 3 different ways to reach from start ...

Read More

Complex Number Multiplication in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have two strings that are representing complex numbers, we have to parse them and perform complex number multiplication, then return result as a string.So if the input is like “1+-1i” and “1+-1i”, then the result will be “0+-2i”.To solve this, we will follow these steps −aa := a pair of real and imaginary of first complex numberbb := a pair of real and imaginary of second complex numberx := aa.real * bb.real – aa.img*bb.imgy := aa.real * bb.img + aa.img*bb.realreturn the string as “x+yi”Let us see the following implementation to get better understanding −Example#include using namespace std; ...

Read More

Unique Paths II in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 285 Views

Suppose there is a robot is located at the top-left corner of a n x m grid (n rows and m columns). The robot can only move either down side or right side at any point in time. The robot wants to reach the bottom-right corner of the grid (marked 'END in the diagram below).Some cell in the grid is marked, that will be considered as obstacles. So we have to find how many possible unique paths are there? For example if the grid is like [[0, 0, 0], [0, 1, 0], [0, 0, 0]], then the grid will be ...

Read More

Simplify Path in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have an absolute path for a file (Like Unix File system), we have to simplify it. Or in other words, we have to convert it to the canonical path. In the UNIX-style file system, a period ‘.’ refers to the current directory. And a double period ‘..’ moves the directory up a level (Parent directory). The properties of canonical paths are as follows.Path must always begin with a slash /There must be only a single slash / between two directory names.Last directory name (if it exists) must not end with a trailing /.Canonical path must be the shortest ...

Read More

Set Matrix Zeroes in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Consider we have a matrix, in that matrix if one element is 0, then make the entire row and column of that matrix to 0. The conversion will be in-place. So if the matrix is −101111111Then the output will be −000101101Let us see the steps −n := number of rows, m := number of columns, set flag := falseif mat[0, 0] = 0, then set flag := trueset row := false, and col := falsefor i in range 1 to nif mat[i, 0] = 0, then set col := True and break the loopfor i in range 1 to mif ...

Read More

Search a 2D Matrix in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 490 Views

Suppose we have write an efficient algorithm to searches for a value in one m x n matrix. This matrix has some properties like below −Each row is sorted from left to rightThe first number of each row is greater than the last integer of the previous row.So if the matrix is like −1357101116202330345053627898And if the target value is 16, then the output will be True.Let us see the steps −n := number of rows, if n is 0, then return false, m := number of columns, if m = 0, then return falselow := 0 and high := n ...

Read More
Showing 1791–1800 of 3,768 articles
« Prev 1 178 179 180 181 182 377 Next »
Advertisements