Server Side Programming Articles - Page 1681 of 2646

Maximum mirrors which can transfer light from bottom to right in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:28:57

241 Views

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 More

Maximum number by concatenating every element in a rotation of an array in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:25:59

778 Views

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 More

Count no. of columns that are not sorted in increasing order in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:24:04

283 Views

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

Count minimum steps to get the given desired array in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:22:13

391 Views

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 More

Count minimum right flips to set all values in an array in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:19:10

305 Views

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 More

Count minimum number of “move-to-front” moves to sort an array in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:17:26

1K+ Views

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 More

Count minimum bits to flip such that XOR of A and B equal to C in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:16:37

412 Views

We are given with three binary sequences A, B and C of length N. Each sequence represents a binary number. We have to find no. of flips required of bits in A and B such that XOR of A and B results in C. A XOR B becomes C.First of all let us learn about truth table of XOR operation −XYX XOR Y000011101110From the above table we observe that for the same values in X and Y, X XOR Y results 0 else it results 1. So this will be helpful for finding bits to be flipped in A and ... Read More

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

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

426 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 i

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

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, 2 → 2, 3→ 1, 4→ 3, 5→ 5Explanation − The highest element is 5, the output shows the number of times each element appears in the array.InputArr[]= { 1, 4, 4, 5, 5, 5, 5 }Output1→ 1, 2 →0, 3→ 0, 4→ 2, 5→ 4Explanation − The highest element ... Read More

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

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

512 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 binary sequence so the only choice to put digits at any place is 0 and 1. For n bits at first and second half, no. of possible combinations are −n bits with all zeros (0 1’s) nC0= 1n bits with 1 1’s nC1n bits with 2 1’s nC2..n bits with ... Read More

Advertisements