@ross: I couldn't get reddy's solution. Please explain.
On Sun, Jun 5, 2011 at 10:50 PM, Deepak Jha deepak.127.0@gmail.comwrote:
the below solution should work given the input array is sorted ( I am
assuming ascending order)
void rearrangeArray(int[] a, int[] b){
int m = a.length;
int
the below solution should work given the input array is sorted ( I am
assuming ascending order)
void rearrangeArray(int[] a, int[] b){
int m = a.length;
int n = b.length;
int i = m - 1;
int j = 0;
while((i =0) (j = n-1)){
if(a[i] b[j]){
int temp = a[i];
a[i] = b[j];
b[j] = temp;
}
i--;
j++;
}
}
Please try this solution. And tell if it fails at any case. If it works
fine, I will tell the logic.
#include stdio.h
#include stdlib.h
void merge(int *a, int m, int *b, int n)
{
int i, j, k;
int t;
i = j = 0;
k = -1;
while ( i m a[i] b[j] ) {
i++;
it can be done in O(m) . Use something like binary search .
code is here ...
#includestdio.h
void splitMN(int a[],int m , int b[], int n){
int al = 0 , bl = 0 ;
int ah = m-1 , bh = n-1 ;
int ai = (ah+al+1)/2;
int bi = (bh+bl+1)/2;
while(ai+bi!=m){
printf(Enter ai
@sravanreddy: it won't work. Try 3,91,9 and 90,1,8,2,5 . correct me
if i m wrong.
Thanks,
Ankit Sambyal
On Sat, May 28, 2011 at 9:16 PM, ross jagadish1...@gmail.com wrote:
@sravanreddy:
Hey, Nice Solution :) cool!
On May 29, 7:44 am, sravanreddy001 sravanreddy...@gmail.com wrote:
@Ankit, The input should be 2 sorted arrays
Thanks,
Immanuel
On Sun, May 29, 2011 at 10:48 AM, ankit sambyal ankitsamb...@gmail.comwrote:
@sravanreddy: it won't work. Try 3,91,9 and 90,1,8,2,5 . correct
me if i m wrong.
Thanks,
Ankit Sambyal
On Sat, May 28, 2011 at 9:16 PM, ross
Oh I didn't read the question properly, Thanks for pointing out...
On Sat, May 28, 2011 at 10:28 PM, immanuel kingston
kingston.imman...@gmail.com wrote:
@Ankit, The input should be 2 sorted arrays
Thanks,
Immanuel
On Sun, May 29, 2011 at 10:48 AM, ankit sambyal