Sunidhi Bansal has Published 1100 Articles

Count index pairs which satisfy the given condition in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 28-Jul-2020 11:14:19

303 Views

We are given an array of permutation of first N natural numbers. The goal here is to find the index pairs of elements that satisfy the condition mentioned below −If an array is Arr[], then i, j are indexes, count element pairs such that Arr[i]+Arr[j]=max(Arr[x]) such that iRead More

Count frequencies of all elements in array in O(1) extra space and O(n) time in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 28-Jul-2020 11:11:32

1K+ Views

We are given with an array of elements ranging from values 1 to n. Some elements are repeated, and some are missing. The goal is to find the frequencies of all elements in O(n) time and O(1) extra space.InputArr[]= { 1, 2, 2, 3, 4, 4, 4, 5 }Output1→ 1, ... Read More

Count even length binary sequences with same sum of first and second half bits in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 28-Jul-2020 11:09:54

381 Views

We are given several bits n as input for a binary sequence. The goal here is to find the binary sequence of length 2n such that the sum of its first and second half bits is equal. First n bits and next n bits have the same sum.We have a ... Read More

Count elements such that there are exactly X elements with values greater than or equal to X in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 28-Jul-2020 11:07:40

429 Views

We are given with an array of integers. The goal is to find the count of elements in the array that satisfy the following condition −For each element the count of numbers greater than or equal to it present in the array should be exactly equal to it. Excluding the ... Read More

Count elements less than or equal to a given value in a sorted rotated array in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 28-Jul-2020 11:06:55

394 Views

We are given with an array of integers. The array is a sorted rotated array. The goal is to find the number of elements in the array that are equal to or less than the given number K.Approach is to traverse the whole array and count such elements which are ... Read More

Maximum count of pairs which generate the same sum in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 28-Jul-2020 11:04:40

548 Views

We are given with an array of integers. The goal is to find the maximum number of pairs in the array that when added produce the same sum. We have to find the maximum count of such pairs.InputArr[]= { 1, 2, 3, 4, 2 }OutputMaximum count of pairs with same ... Read More

Maximum count of equal numbers in an array after performing given operations in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 28-Jul-2020 11:02:35

936 Views

We are given with an array of integers. The goal is to find the maximum numbers in array that are equal after performing given operations −Select two elements a[i] and a[j] such that i != j andIncrement a[i] and decrement a[j] ( a[i]++, a[j]-- )We will take the sum of ... Read More

Maximum consecutive numbers present in an array in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 28-Jul-2020 11:01:47

2K+ Views

We are given with an array of positive integers. The goal is to find the maximum number of consecutive numbers present in it. First of all we will sort the array and then compare adjacent elements arr[j]==arr[i]+1 (j=i+1), if difference is 1 then increment count and indexes i++, j++ else ... Read More

Maximum array sum that can be obtained after exactly k changes in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 28-Jul-2020 10:59:01

598 Views

We are given with an array of positive and negative integers and a number K. The task is to find the maximum sum of the array after K changes in it’s elements. The single change operation here multiplies the single element by -1.Approach used will be to convert every negative ... Read More

Maximum and minimum sums from two numbers with digit replacements in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 28-Jul-2020 10:57:06

243 Views

We are given with two positive numbers num1 and num2. The goal is to find the minimum sum and maximum sum possible of these two after a digit replacement in both of them. We are allowed to replace digits from each of numbers in both of numbers. Suppose num1 is ... Read More

Advertisements