There is an array A[N] of N numbers. You have to compose an array Output[N] such that Output[i] will be equal to multiplication of all the elements of A[N] except A[i]. For example Output[0] will be multiplication of A[1] to A[N-1] and Output[1] will be multiplication of A[0] and from A[2] to A[N-1].
Solve it without division operator and in O(n).
Rotate an n-element vector left by i positions in time proportional to n with just a dozen bytes of extra space. For instance, with n=8 and i=3, the vector abcdefgh is rotated to defghabc
enum {RED,BLUE,GREEN}; struct Ball { /*...*/ int color; };
int ColorOfBall(Ball b) { return b.color; } Ball arr[SIZE];
The array arr consists of balls of with one of the three colours (Red,Green,Blue). Now we need to sort the array in such a way that all the Red coloured balls come first, followed by blue and then green.
The restriction is that call to function ColorOfBall is a very costly operation. You have to use it as less as possible. (In other words we would be looking for the solution with least number of calls to the function ColorOfBall.)
You have two sorted integer arrays and the larger array has room for the second. Merge the smaller array into the larger one, in O(n) time and O(1) space.
You are given a sequence of numbers from 1 to n-1 with one of the numbers repeating only once. (example: 1 2 3 3 4 5). how can you find the repeating number? what if i give you the constraint that you can't use a dynamic amount of memory (i.e. the amount of memory you use can't be related to n)? what if there are two repeating numbers (and the same memory constraint?)
Given an array, Design an algorithm to find the subvector with the sum closest to zero. extenstion: What if we wished to find teh subvector with the sum closest to a given real number t?
Given a consecutive list of numbers from a to b, one number is removed. The list is then scrambled. Find the missing number. int find(int a, int b, int *array); hint: sum(1 to n) is n(n+1)/2 using the same logic, sum(a to b) is (b-a)/2 * (b+a)