Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 227 of 377

Strange Printer in C++

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

Suppose there is a strange printer It has some requirements −The printer can print only a sequence of the same character each time.In each turn, the printer can print new characters starting from and ending at any places, and will cover the original existing characters.So if we have a string consists of lower letters, our task is to count the minimum number of turns the printer needed in order to print it.So if the input is like “aaabba”, then it will take 2 turns, first prints aaaaa then b’s by replacing the characters.To solve this, we will follow these steps ...

Read More

Kth Smallest Number in Multiplication Table in C++

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

Suppose we know about one Multiplication Table. But could we find out the k-th smallest number quickly from the multiplication table? So if we have to height m and the length n of a m * n Multiplication Table, and one positive integer k, we have need to find the k-th smallest number in this table.So if m = 3 and n = 3 and k is 6, then the output will be 4., this is because the multiplication table is like −1231123224633696th smallest element is 4 as [1, 2, 2, 3, 3, 4, 6, 6, 9]To solve this, we ...

Read More

24 Game in C++

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

Suppose we have four cards; these cards are holding some number from 1 to 9. We have to check whether they could operate through some operators like +, -, *, /, to get 24. So if we have some numbers like [4,9,2,6], then we can get 24 by (4 * 9) – (2 * 6), answer will be true.To solve this, we will follow these steps −epsilon := 10.0^-5Define a function solve(), this will take an array v,if size of v is same as 1, then −return true when |v[0] - 24.0|

Read More

Redundant Connection II in C++

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

Suppose we have a rooted tree. This is a directed graph such that, there is exactly one node (which is the root) for which all other nodes are descendants of this node, and every node has exactly one parent, except for the root node. Root has no parents.In the given input a directed graph that started as a rooted tree with N nodes (All values are unique), with one additional directed edge added. The added edge has two different vertices chosen from 1 to N, and was not an edge that already existed.Graph will be a 2D-array of edges. Each ...

Read More

Maximum Sum of 3 Non-Overlapping Subarrays in C++

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

Suppose we have one array called nums of positive integers, we have to find three non-overlapping subarrays with maximum sum. Here each subarray will be of size k, and we want to maximize the sum of all 3*k entries.We have to find the result as a list of indices representing the starting position of each interval. If there are multiple answers, we will return the lexicographically smallest one.So if the input is like [1, 2, 1, 2, 6, 8, 4, 1] and k = 2, then the result will be [0, 3, 5], so subarrays are [1, 2], [2, 6], ...

Read More

Stickers to Spell Word in C++

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

Suppose we have N different types of stickers. In each type of sticker has a lowercase English word on it. We would like to spell out the given target string by cutting individual letters from our collection of stickers and rearranging them. We can use each sticker more than once if needed, and we have infinite quantities of each sticker.We have to find the minimum number of stickers that we need to spell out the target? If the task is impossible, return -1.So if the input is like [“dog”, “sentence”, ”antenna”], and target is “dance”, then the answer will be ...

Read More

Random Pick with Blacklist in C++

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

Suppose we have a blacklist called B. This is holing unique integers from range [0, N), we have to define a function to return a uniform random integer from range [0, N) which is NOT in B. We will try to make this function more optimized by reducing random(). function call. Suppose the input array is likeTo solve this, we will follow these steps −Define one mapWe will initialize with N and array v.for initalize i := 0, when i < size of v, update (increase i by 1), do −if v[i] < N, then:, m[v[i]] := -1M := N ...

Read More

Range Module in C++

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

Suppose we want a Range Module. This is a module that tracks ranges of numbers. Our task is to design and implement the following interfaces in an efficient manner.addRange(left, right). This will the half-open interval [left, right), tracking every real number in that interval. Now, adding an interval that partially overlaps with currently tracked numbers should add any numbers in the interval that are not already tracked.queryRange(left, right) . This will return true when every real number in the interval [left, right) is currently being tracked.removeRange(left, right), this will stop tracking every real number currently being tracked in the interval ...

Read More

Find K-th Smallest Pair Distance in C++

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

Suppose we have an integer array; we have to find the kth smallest distance among all the pairs. The distance of a pair (A, B) is actually the absolute difference between A and B. So if the input is like [1, 3, 8], then all possible pairs are [1, 3], [3, 8], [1, 8], then when k = 2, the second smallest distance is 5 (8 - 3).To solve this, we will follow these steps −n := size of nums, x := 0for initialize i := 0, when i < n, update (increase i by 1), do −x := maximum ...

Read More

Cherry Pickup in C++

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

Suppose we have one N x N grid, this is filled with cherries. Each cell has one of the possible integers as follows −0 − Indicates cell is empty, so we can pass through1 − Indicates cell contains a cherry, that we can pick up and pass through-1 − Indicates the cell is containing a thorn that blocks the wayWe have to collect maximum number of cherries using these few rules −Start from position (0, 0) and end at (N-1, N-1) by moving right or down through valid path cellsAfter reaching the cell (N-1, N-1), returning to (0, 0) by ...

Read More
Showing 2261–2270 of 3,768 articles
« Prev 1 225 226 227 228 229 377 Next »
Advertisements