Arnab Chakraborty has Published 4293 Articles

Find largest d in array such that a + b + c = d in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 09:56:32

156 Views

Suppose we have a set of integers. We have to find a number ‘d’, where d = a + b + c, and we have to maximize (a + b + c), all a, b, c, and d are present in the set. The set will hold at least one ... Read More

Find k numbers which are powers of 2 and have sum N in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 09:53:04

191 Views

Suppose we have two numbers N and K. The task is to print K numbers, which are the power of 2 and their sum is N. If it is not possible, then return -1. Suppose N = 9 and K = 4, then the output will be 4 2 2 ... Read More

Find Intersection of all Intervals in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 09:50:23

852 Views

Suppose, we have N intervals in the form {L, R}, the L is the starting time, and R is the ending time. We have to find an intersection of all intervals. An intersection is an interval that lies within all of the given intervals. If no such found, return -1. ... Read More

Find indices of all occurrence of one string in other in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 09:42:14

3K+ Views

Suppose we have string str, and another substring sub_str, we have to find the indices for all occurrences of the sub_str in str. Suppose the str is “aabbababaabbbabbaaabba”, and sub_str is “abb”, then the indices will be 1 9 13 18.To solve this problem, we can use the substr() function ... Read More

Find if the given number is present in the infinite sequence or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 08:15:27

253 Views

Suppose we have three integers a, b and c. Suppose in an infinite sequence, a is the first term, and c is a common difference. We have to check whether b is present in the sequence or not. Suppose the values are like a = 1, b = 7 and ... Read More

Find if an expression has duplicate parenthesis or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 08:08:01

346 Views

Consider we have an expression exp, and we have to check whether the exp has a duplicate set of parentheses around it or not. An expression will have duplicate parentheses if one sub-expression will be surrounded by more than one parentheses set. For example, if the expression is like −(5+((7−3)))Here ... Read More

Find if an array contains a string with one mismatch in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 08:05:55

190 Views

Suppose we have a string s, and another array of strings A. We have to find whether the array is containing a string with the one-character difference from the current string of different lengths. Suppose the string is like “banana”, and the array looks like [“bana”, “orange”, “banaba”, “banapy”], the ... Read More

Find gcd(a^n, c) where a, n and c can vary from 1 to 10^9 in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 08:01:30

83 Views

We have to find the GCD of two numbers of which one number can be as big as (109 ^ 109), which cannot be stored in some data types like long or any other. So if the numbers are a = 10248585, n = 1000000, b = 12564, then result ... Read More

Find frequency of each element in a limited range array in less than O(n) time in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 07:58:53

330 Views

Suppose we have an array of integers. The array is A, and the size is n. Our task is to find the frequency of all elements in the array less than O(n) time. The size of the elements must be less than one value say M. Here we will use ... Read More

Find four elements a, b, c and d in an array such that a+b = c+d in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 07:55:06

819 Views

Suppose we have a list of integers. Our task is to find four distinct integers as two pairs like (a, b) and (c, d), such that a+b = c+d. If there are multiple answers, then print only one. Suppose the array elements are like: A = [7, 5, 9, 3, ... Read More

Advertisements