Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Sunidhi Bansal
Page 51 of 81
Count index pairs which satisfy the given condition in C++
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 i
Read MoreCount minimum number of "move-to-front" moves to sort an array in C++
We are given with an array of numbers between 1 to n. The goal here is to find the no. of ‘move to front’ operations required to sort the given array. The array has no repetition. The ‘move to front’ operation picks an element and places at first position, here at index 0.We will traverse the array from end, if element is at the correct position then no move else move is required. For elements from 1 to n, the correct position in the array of element arr[i] should be at index i+1. arr[0] should be 1, arr[1] should be ...
Read MoreCount minimum right flips to set all values in an array in C++
We are given an array of 0s and 1s which represent the state of bulbs that are connected with the same wire in sequence. 0 represents that the bulb is OFF and 1 represents that the bulb is ON. For such a sequence of N bulbs, if the switch of the bulb is pressed then all bulbs on right, (i+1 th till n) change their previous stare, from ON to OFF or from OFF to ON.For the given state of all bulbs, the goal is to find the minimum switches to be pressed to turn all of them ON. [ ...
Read MoreCount minimum steps to get the given desired array in C++
We are given with an array target[] which has numbers in it. We must find the minimum steps in which array with all zeros [0, 0, 0, 0…] can be converted to target using following two operations only −Increment operation − all elements can be incremented by 1, each increment operation can be counted individually in steps. ( for n increments in n elements steps=n )Doubling operation − the whole array is doubled. For all elements it is counted once. ( each doubling operation doubles all elements’ value, count it as 1 in stepsThe goal is to find the minimum ...
Read MoreCount no. of columns that are not sorted in increasing order in C++
We are given an array of strings each of the same length. The goal is to find columns, ( matrix of strings ) that are not sorted in increasing order. For example, each first character in string is compared with the first character of the next string and so on till the last string. If they are not in increasing order, increase the count. Do this for all second characters, then third characters of all strings and so on till the last character.InputArr[]= { “abc”, “bcd”, “def” }OutputCount of columns: 0Explanation − for each column,Column 1: character at index 0 : a
Read MoreMaximum number by concatenating every element in a rotation of an array in C++
We are given a circular array of numbers. A circular array is the one in which the elements are arranged such that the first element is treated as just next to the last element. These are used to implement queues.Each element has the same or different digit count. The goal is to create the highest number possible by concatenating the numbers, using rotation of elements if required. We will do this by finding the highest leftmost digit among all the leftmost digits of all elements. The number with the highest leftmost digit will take the first place.If it is at ...
Read MoreMaximum mirrors which can transfer light from bottom to right in C++
We are given with a square matrix which contains 0’s and 1’s only. 0 represents a blank or empty place and 1 means obstacle. We must find a number of mirrors that can be placed at empty cells such that these mirrors can transfer light from bottom to right. This is possible when, mirror is placed at index [i, j] and for all cells on the right in that particular row ( i ) and cells in the bottom ( j ) in that particular column have no obstacle.If the mirror is at A[i][j], then all A[i+1 to n][ j ...
Read MoreMaximize the value of x + y + z such that ax + by + cz = n in C++
We are given with integers a, b, c, n. The goal is to maximize the sum of x, y and z such that ax+by+cz=n.From above formula, cz=n-(ax+by) z= (n- (ax+by))/cBy fixing x and y, calculate z using the above formula, for each x, y and z. Calculate sum and store the maximum such sum obtained.Inputn = 6, a = 3, b = 4, c = 5;Outputmaximum x+y+z is 2.Explanation − for x=2, y=0 and z=0 ax+by+cz=n.3*2+0*4+0*5=6 = nInputn = 4, a = 3, b = 1, c = 2;Outputmaximum x+y+z=4Explanation − for x=0, y=4 and z=4 ax+by+cz=n.0*3+4*1+0*2=4 = nApproach used ...
Read MoreMaximize arr[j] – arr[i] + arr[l] – arr[k], such that i < j < k < l in C++
We are given with an array of integers. The goal is to maximize the value of expression −arr[j]-arr[i] + arr[l]-arr[k] ; i
Read MoreCount common characters in two strings in C++
We are given with the two strings let’s say str1 and str2 and the task is to find the count of common characters in two strings i.e. if str1[i] = str[j], then they will be considered as a pair and count will increased to 1 and if str1[i]!=str2[j] then they willn’t be considered as a pair and count willn’t increase to 1.For ExampleInput − str1 = “hello” str2 = “heoo” Output − count is: 3Explanation − str1[0] = str2[0] i.e. h ; str1[1] = str2[1] i.e. e ; str1[2]!=str2[2] i.e. l and o; str1[3]=str2[3] i.e. o. So, the ...
Read More