Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 169 of 377

Non-overlapping Intervals in C++

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

Suppose we have a collection of intervals; we have to find the minimum number of intervals we need to remove to make the rest of the intervals non-overlapping. So if the intervals are [[1, 2], [2, 3], [3, 4], [1, 3]], then the output will be 1, as we have to remove [1, 3] to make all others are non-overlapping.To solve this, we will follow these steps −n := size of arrayif n is 0, then return 0count := 1sort the array based on the end time of the intervalsend := end date of the first intervalfor i in range ...

Read More

Convert to Base -2 in C++

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

Suppose we have a number N, we have to find a string consisting of "0"s and "1"s that represents its value in base -2 (negative two). The returned string should have no leading zeroes, unless the string is exactly "0". So if the input is like 2, then the output will be “110”, as (-2)^2 + (-2)^1 + (-2)^0 = 2.To solve this, we will follow these steps −ret := an empty stringif N = 0, then return “0”while N is non 0rem := N mod (– 2)N := N / (-2)if rem < 0 and rem := rem + ...

Read More

Water and Jug Problem in C++

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

Suppose we have two jugs with capacities x and y liters. There is an infinite amount of water supply available to us. Now we need to determine whether it is possible to measure exactly z liters using these two jugs. If z liters of water are measurable, we must have z liters of water contained within one or both buckets by the end.We can do these few operations −Fill any of the jugs fully with water.Empty any of the jugs.Pour water from one jug into another till the other jug is completely full or the first jug itself is empty.So ...

Read More

Delete Node in a BST in C++

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

Suppose we have a binary search tree. We will take one key k, and we have to delete the given key k from the BST, and return the updated BST. So if the tree is like −And the key k = 3, then the output tree will be −To solve this, we will follow these steps −Define a method called deleteRoot() to delete the root node, this will work as followsif root is null, then return nullif root has no right subtree, then return left of rootx := inorder successor of rootset left of x as left := left of ...

Read More

Number of Enclaves in C++

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

Suppose we have given a 2D array A, now each cell is 0 (representing sea) or 1 (representing land) Here a move consists of walking from one land square 4-directionally to another land square, or off the boundary of the grid. We have to find the number of land squares in the grid for which we cannot walk off the boundary of the grid in any number of moves. So if the grid is like −0000101001100000The answer will be 3, as there are three ones enclosed by 0s, and one 1 is not enclosed.To solve this, we will follow these ...

Read More

Largest Divisible Subset in C++

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

Suppose we have a set of distinct positive integers, we have to find the largest subset such that every pair like (Si, Sj) of elements in this subset satisfies: Si mod Sj = 0 or Sj mod Si = 0.So if the input is like [1, 2, 3], the possible result may come like [1, 2] or [1, 3]To solve this, we will follow these steps −Create an array ret, set endpoint := 0, retLen := 1, n := size of numsif n is 0, then return empty setsort nums arraycreate two arrays len and par of size n, initialize ...

Read More

Minimum Number of Arrows to Burst Balloons in C++

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

Suppose there are few spherical balloons spread in two-dimensional space. For each balloon, there are the start and end coordinates of the horizontal diameter. Start is always smaller than end. There will be at most 104 balloons. One arrow can be shot up exactly vertically from different points along the x-axis. A balloon whose position is xstart to xend bursts by an arrow shot at x if xstart = x = xend. There is no limit to the number of arrows that can be shot. Assume that an arrow once shot keeps travelling up infinitely. We have to find the ...

Read More

Sentence Screen Fitting in C++

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

Suppose we have a rows x cols screen and a sentence represented by a list of non-empty words, so we have to find how many times the given sentence can be fitted on the screen. There are certain properties −A word will not be split into two lines.The order of words in the sentence must not be changed.There will be only one space between two words.The total number of words in the sentence won't exceed 100.The length of each word is greater than 0 but less than 10.1 ≤ rows, cols ≤ 20, 000.So if the input is like rows ...

Read More

Video Stitching in C++

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

Suppose we have a series of video clips from a sporting event that lasted T seconds. Now these video clips can be overlapping with each other and have varied lengths. Here each video clip clips[i] is an interval − it starts at clips[i][0] time and ends at clips[i][1] time. We can cut these clips into segments freely − We have to find the minimum number of clips needed so that we can cut the clips into segments that cover the entire sporting event ([0, T]). If the task is impossible, return -1. So if the input is like [[0, 2], ...

Read More

Super Pow in C++

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

Suppose we have to calculate a^b mod 1337 where a is one positive integer and b is an extremely large positive integer given in the form of an array. So if a = 2 and b = [1, 0] then the output will be 1024To solve this, we will follow these steps −Define powerMod() method this takes base and powerm := 1337, ret := 1while power is not 0if power is odd, then ret := ret * base mod mbase := base^2 mod mpower := power / 2return retDefine superPower(), this takes a and bif size of b = 0, ...

Read More
Showing 1681–1690 of 3,768 articles
« Prev 1 167 168 169 170 171 377 Next »
Advertisements