[algogeeks] Re: Merging Sorted Arrays

2011-07-07 Thread Yuduo Zhou
Yep, I was wrong. for (i = 0; i < m; i++){ if (a[i] > b[0]){ swap(a[i], b[0]); push b[0] to the end of array-b as far as possible here. } } Then it's not O(m+n) anymore. O(mn) instead. On Jul 7, 4:33 pm, Yuduo Zhou wrote: > I remember there is an swap using

[algogeeks] Re: Merging Sorted Arrays

2011-07-07 Thread Yuduo Zhou
I remember there is an swap using XOR that uses no extra space. It's also O(1). assume we have a O(1) function: swap(a, b) a[m], b[n], all sorted separately. for (i = 0; i < m; i++){ if (a[i] > b[0]){ swap(a[i], b[0]); if (b[0] > b[1]){ swap(b[1], b[0]); }

[algogeeks] Re: GOOGLE Q3

2011-07-07 Thread Yuduo Zhou
Given 77, it can be divided into 77-77-77 or 777-777 so it will return 77-77-77 with a quality of 6, other than the other way, which gives quality of 4. Also , a good group like 229, can be seen as 22-9, which gives a excellent group. I assume first looking groups with 2 digits? On Jul 7, 2:1