Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 301 of 377

Minimizing array sum by applying XOR operation on all elements of the array in C++

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

DescriptionGiven an array of size, N. Find an element X such that the sum of array elements should be minimum when XOR operation is performed with X and each element of an array.If input array is: arr [] = {8, 5, 7, 6, 9} then minimum sum will be 30 Binary representation of array elments are: 8 : 1000 5 : 0101 7 : 0111 6 : 0101 9 : 1001 If X = 5 then after performing XOR sum will be 30: 8 ^ 5 = 13 5 ^ 5 = 0 7 ^ 5 = 2 6 ^ ...

Read More

Minimum Cost To Make Two Strings Identical in C++

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

Suppose we have two strings A and B, and another two cost values like CostA, and CostB. We have to find the minimum cost to make A and B identical. We can delete characters from string, the cost for deleting from string A is CostA, and cost for deleting from string B is CostB. Cost of removing all characters from a string is same. Suppose the string A = “wxyz”, B = “wyzx”, CostA is 10 and CostB is 20. So the output will be 30. If we delete x from both the strings, then A and B will be ...

Read More

Minimum Index Sum for Common Elements of Two Lists in C++

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

Suppose two person wants to choose different cities, they have listed out the cities in different list, we have to help the, to find common choices. So we need to find those cities, those are marked by both of them.This operation is very similar to the set intersection property, we will take two lists as set, then perform the set intersection to get the common elements.Example#include #include #include using namespace std; vector commonInterest(string set1[], int n1, string set2[], int n2) {    vector v(min(n1, n2));    vector::iterator it;    // Sorting both the list    sort(set1, set1 ...

Read More

Find Corners of Rectangle using mid points in C++

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

Suppose we have a rectangle ABCD, but we have only the coordinates of the mid points P and Q, and the length of the rectangle L.Our task is to find the coordinates of A, B, C and D using the coordinates of P and Q, and the length of side L. For example, if P is (1, 0), and Q is (1, 2), and L is 2, then A, B, C, D will be respectively (0, 0), (0, 2), (2, 2). (2, 0).There can be three cases that can occur.The rectangle is horizontal, so AD and BC are parallel to ...

Read More

Find the GCD of N Fibonacci Numbers with given Indices in C++

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

Here we have to find the GCD of n Fibonacci terms with the given indices. So at first we have to get the maximum index, and generate Fibonacci terms, some Fibonacci terms are like this: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ….. The index is starts from 0. So the element at 0th index is 0. If we have to find gcd of Fibonacci terms at indices {2, 3, 4, 5}, then the terms are {1, 2, 3, 4}, so GCD of these numbers are 1.We will use one interesting approach to do this task. To ...

Read More

Find the Rotation Count in Rotated Sorted array in C++

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

Consider we have an array, which is rotated sorted array. We have to find number of rotations are required to sort the array. (We will consider rotation right to left.)Suppose the array is like: {15, 17, 1, 2, 6, 11}, then we have to rotate the array two times to sort. The final order will be {1, 2, 6, 11, 15, 17}. Here output is 2.The logic is simple. If we notice, we can see that the number of rotation is same as the value of index of minimum element. So if we get the minimum element, then its index ...

Read More

Finding LCM of more than two (or array) numbers without using GCD in C++

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

We have an array A, we have to find the LCM of all elements without using the GCD operation. If the array is like {4, 6, 12, 24, 30}, then the LCM will be 120.The LCM can be calculated easily for two numbers. We have to follow this algorithm to get the LCM.getLCM(a, b) −begin    if a > b, then m := a, otherwise m := b       while true do          if m is divisible by both a and b, then return m             m := m + ...

Read More

Floor and Ceil from a BST in C++

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

Here we will see, how to find the Floor and Ceiling value from BST. For example, if we want to make a memory management system, where free nodes are arranged in BST. Find best fit for the input request. Suppose we are moving down the tree with smallest data larger than the key value, then there are three possible cases.Root is the key. Then root value is the ceiling valueIf root data < key, then the ceiling value will not be at the left subtree, then proceed to right subtree, and reduce the problem domainIf root data > key, then ...

Read More

Check for balanced parentheses in an expression in C++

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

Suppose we have an expression. The expression has some parentheses; we have to check the parentheses are balanced or not. The order of the parentheses are (), {} and []. Suppose there are two strings. “()[(){()}]” this is valid, but “{[}]” is invalid.The task is simple; we will use stack to do this. We should follow these steps to get the solution −Traverse through the expression until it has exhaustedif the current character is opening bracket like (, { or [, then push into stackif the current character is closing bracket like ), } or ], then pop from stack, ...

Read More

Check for Palindrome after every character replacement Query in C++

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

Consider we have a string and some queries in set Q. Each query contains a pair of integers i and j. and another character c. We have to replace characters at index i and j with the new character c. And tell if the string is palindrome or not. Suppose a string is like “AXCDCMP”, if we use one query like (1, 5, B), then the string will be “ABCDCBP”, then another query like (0, 6, A), then it will be “ABCDCBA”, this is palindrome.We have to create one query using indices i, j, then replace the characters present at ...

Read More
Showing 3001–3010 of 3,768 articles
« Prev 1 299 300 301 302 303 377 Next »
Advertisements