[algogeeks] Re: Missing numbers

2009-07-30 Thread Vikram Venkatesan
*for i=1 to sumofXY/2* *if (xorofXY XOR i XOR (sumofXY-i)) is zero* *then x is i, y is (sumofXY-i)* *endfor* Channa, is this logic based on the assumption/fact that no other other pair of numbers (m, n) can have the same XOR and SUMMATION as that of the (x, y) pair? If so, could you please

[algogeeks] Re: array of 0s and 1s

2007-11-13 Thread Vikram Venkatesan
@Dave, *Otherwise, set the even position to 0 and the odd position to 1.* I think your solution might be inserting 0's and 1's into the array from nowhere (thus filling the whole array with alternating 0's and 1's up to the given size !). The question is to re-arrange existing elements in the

[algogeeks] Re: array of 0s and 1s

2007-11-13 Thread Vikram Venkatesan
switch them. Switching a 1 and a 0 simply means storing 0 where the 1 was and storing 1 where the 0 was; there is no need to use the usual code to interchange two values. Dave On Nov 13, 8:37 am, Vikram Venkatesan [EMAIL PROTECTED] wrote: @Dave, *Otherwise, set the even position to 0

[algogeeks] Re: spiral matrix..

2006-12-05 Thread Vikram Venkatesan
Hi, I think the question is not to FORM A MATRIX, but to PRINT the elements in the form of spiral matrix, where the problem of SEQUENTIAL OUTPUT comes... -Vikram On 12/6/06, Gene [EMAIL PROTECTED] wrote: hijkl wrote: this question was asked by Google.. Write a program of spiral

[algogeeks] Re: Arranging arrays in to two sets.

2006-11-16 Thread Vikram Venkatesan
Hi Ksitami, In the first algorithm, what if the CYLCE OF REPLACEMENTS sorts the whole array(I mean, all the elements are visited during the 1st iteration itself, thus creating a COMPLETE CYCLE of the array, putting it in the right order), and the array gets to the FINAL position (i.e.

[algogeeks] Re: Nice question!!

2006-06-26 Thread Vikram Venkatesan
Hi, A similar but straightfoward O(n^2) solution ;-) For each element a[i], traverse on either side of the array with a[i] as the pivot until you reach elements a[j]a[i] and a[k]a[i](Two sides). Keep track of the current summations from a[i] (Probably have an array of sub-array

[algogeeks] Re: find the most occured (more than N/2 times , where N is the length of the array) element in an array

2006-06-20 Thread Vikram Venkatesan
Hi,The problem with that PAIRING solution is that, at each step, some information is lostSay, the array is 2,5,2,7,2,8,2,1While taking elements pair by pair, first, since 2 !=5 , we skip it... (At this step itself, the information about the occurence of '2' is lost) The same happens in the

[algogeeks] Re: find the most occured (more than N/2 times , where N is the length of the array) element in an array

2006-06-20 Thread Vikram Venkatesan
correct me if i am wrongRegards,VikramOn 6/21/06, Pradeep Muthukrishnan [EMAIL PROTECTED] wrote: Please read the question properly...The number can be a majorityelement only if it repeats more than n/2 timesIn your example itdoesnt...On 6/20/06, Vikram Venkatesan [EMAIL PROTECTED] wrote: Hi

[algogeeks] Re: puzzle from code4bill

2006-01-23 Thread Vikram Venkatesan
Hi, It can be derived as follows... Let f(n) denote the no. of ways in which 'n' steps can be climbed... So, for climbing 'n' steps, the possible combinations are, 1. Climb one step initially.. so, n-1 steps left.. they can be climbed in f(n-1) ways, OR 2. Climb 2 steps initally... so, n-2

[algogeeks] Re: Sum of sub array

2006-01-05 Thread Vikram Venkatesan
I agree with phoenixinter... whats the problem with that?? its the obvious solution, provided O(n) precomputation time... Abhi, can you explain whether there is any problem with that solution??