## kunal.id89

BAN USERValue of total will depend upon last iteration so what is the need of loop? i guess u missed something..

- kunal.id89 August 11, 20123*rand(3) will not give 1 and 2.

- kunal.id89 August 11, 2012if it not a homogenous solution???

solution will be more concentrated at base..

plz elaborate by giving some example.. i am unable to figure out..

- kunal.id89 July 19, 2012swap(i,j) is getting replaced by

temp=a;a=b;b=temp

since you have not used curly braces after if, so only first statement is considered inside if block.

so temp=a will not execute as the condition is false.

rest two line a=b;b=temp will execute making a=10 and b=0.

correction:

if(i>j){

swap(i,j);

}

but i dont think we have any other method to do in linear time..

- kunal.id89 July 13, 2012we can solve this in nlogn time using quicksort approach.

while partitioning we will use the API function as the > or < key as to compare the two players.

Ex:

a vs b a

a vs c c

b vs c b

suppose the array was arranged as cba.

take c as pivot and partition the array , it will become acb which is a correct solution..

this method can give different answer depending on the choice of pivot.

appreciate..

- kunal.id89 July 12, 2012can anyone help me with explaining hashing logic..

- kunal.id89 July 12, 2012you have to sort your array first. so time complexity will be O(nlgn).

it can be done using hashing in O(n).

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

Suppose you want to rotate array by K so first reverse last K elements i.e array[n-K+1...K], then reverse array[1..n-k], then reverse entire array array[1...n] and you will get the result.

- kunal.id89 November 22, 2012Example:

array=[1,2,3,4,5,a,b,c]

K=3, here

reverse array[n-K+1... n] so the array will become [1,2,3,4,5,c,b,a].

Now reverse array[1...n-K], array will become [5,4,3,2,1,c,b,a].

Now reverse entire array and array will become [a,b,c,1,2,3,4,5].

Time complexity: O(n), Space complexity: O(n)..