Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 183 of 377

Find a palindromic string B such that given String A is a subsequence of B in C++

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

Suppose we have a string A, we have to find another string B, that will be palindrome. And the given string A will be subsequence of B. The subsequence of a string is a string that can be formed by it by deleting some characters without changing the order of remaining characters. Suppose the string is “cotst”, then generated string will be “contest”. For the input of this program we have chosen A = “ab”, the generated string will be “abba”, this is palindrome.To solve this, we will follow this approach. This is very simple, we will reverse the A, ...

Read More

Find a specific pair in Matrix in C++

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

Suppose there is an n x n matrix mat of integers. we have to find maximum value of mat(c, d) - mat(a, b) over all choices of indexes. Here we have to keep in mind that c > a and d > b. So if the matrix is like −12-1-4-20-8-342138613-4-117-60-410-51The output will be 18. This is because mat[4, 2] - mat[1, 0] = 18 has maximum difference.To solve this we will preprocess the matrix such that index(i, j) stores max of elements in matrix from (i, j) to (n - 1, n - 1) and in the process keeps on ...

Read More

Find a triplet such that sum of two equals to third element in C++

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

Suppose there is an array of n numbers. We have to find three numbers, such that sum of two elements is same as the third one. So if the array is like [5, 32, 1, 7, 10, 50, 19, 21, 2], the output will be 21, 2, 19. If no such element has found, display that message.To solve this, we will follow some steps as follows −Sort the given arrayThen start fixing the greatest element from the last element and traverse the array to find other two numbers which sum up to the third element.Take two pointers j and k, ...

Read More

Bin Packing Problem (Minimize number of used Bins) in C++?

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

In case of given m elements of different weights and bins each of capacity C, assign each element to a bin so that number of total implemented bins is minimized. Assumption should be that all elements have weights less than bin capacity.ApplicationsPlacing data on multiple disks.Loading of containers like trucks.Packing advertisements in fixed length radio/TV station breaks.Job scheduling.ExampleInput: weight[] = {4, 1, 8, 1, 4, 2} Bin Capacity c = 10 Output: 2 We require at least 2 bins to accommodate all elements First bin consists {4, 4, 2} and second bin {8, 2}Lower BoundWe can always calculate a lower ...

Read More

Find alphabet in a Matrix which has maximum number of stars around it in C++

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

Suppose we have a matrix M. This is filled with stars and letters. We have to find which letter has maximum number of stars around it. So if the matrix is like below −Here A and C has 7 stars around it. this is maximum. As A is lexicographically smaller, so it will be the output.The approach is simple, we will count the characters, then when one character has found, then count the stars around it. Also store the value inside a map. From the map where the size is maximum that will be printed.Example#include #include #define MAX 4 ...

Read More

Find duplicate rows in a binary matrix in C++

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

Suppose we a binary matrix. Here we will see how to find the duplicate rows in that matrix. Suppose the matrix is like −110101001001101100110101001001001001There are duplicate rows at position 3, 4, 5.To solve this, we will use the Trie. The Trie is an efficient data structure used for strong and retrieval of data where character set is small. The search complexity is optimal as the key length. So at first we will insert the binary trie. If the newly added row is already present, then that is duplicate.Example#include using namespace std; const int MAX = 100; class Trie {   ...

Read More

Find four factors of N with maximum product and sum equal to N in C++

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

Suppose we have an integer N. The task is to find all factors of N and display the product of four factors of N, such that −Sum of their four factors are equal to NThe product of four factors is maximumSuppose the number is 24, then the product is 1296. As we know all of the factors are 1, 2, 3, 4, 6, 8, 12, 24. We have to choose the factors 6 four times. So 6 + 6 + 6 + 6 = 24. Here the product is maximum.To solve this, we have to find all factors from 1 ...

Read More

Find if there is a rectangle in binary matrix with corners as 1 in C++

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

Suppose we have a binary matrix. We have to find if there is any rectangle or sequence in the given matrix whose all four corners are equal to 1. The matrix is like10010001010001010101The result will be yes. Here one rectangle is present, whose corners are with 1s.101010101To solve this we will use one efficient approach. We will follow these steps −Scan the matrix from top to bottom line by lineFor each line remember each combination of two 1’s and push that into a hash-set.If we ever find that combination again in the later line, we will get our rectangle.Example#include #include ...

Read More

Find intersection point of lines inside a section in C++

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

Suppose we have set of lines in the form y = mx + c. There are sections made by this line and the vertical section. We have to find the intersection point present in the given section or not. Suppose the lines are like −L1 = y = x + 2L2 = y = -x + 7L3 = y = -3L4 = y = 2x - 7And the vertical section is given from x = 2 to x = 4.Here intersection points of L1 and L2 are present inside this section, so the answer will be true.To solve this problem, ...

Read More

Find Maximum dot product of two arrays with insertion of 0's in C++

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

Suppose we have two arrays of positive integers of size m and n. The m > n. We have to maximize the dot product by inserting zeros in the second array. One thing we have to keep in mind that we will not change the ordering of the elements in the given arrays. Suppose the arrays are A = [2, 3, 1, 7, 8], and another array B = [3, 6, 7]. The output will be 107. We can maximize the dot product after inserting 0s at first and third position of the second array. So the product will be ...

Read More
Showing 1821–1830 of 3,768 articles
« Prev 1 181 182 183 184 185 377 Next »
Advertisements