@aakash Johari:
Let a and b be the 2 arrays.
At each stage of the process, if an element of A is greater than B,
then swap the largest element of A with the smallest element of B
and adjust pointers.

A : 2 4 15 12
B : 0.2 1  33 44

Now, 2>0, therefore swap 0 with 12..
Every step of the process, gets in the smallest elemnt of A and swaps
it
with the largest element of B.

Hope its clear.


On Jun 6, 11:15 am, Aakash Johari <[email protected]> wrote:
> @ross: I couldn't get reddy's solution. Please explain.
>
> On Sun, Jun 5, 2011 at 10:50 PM, Deepak Jha <[email protected]>wrote:
>
>
>
>
>
>
>
>
>
> > 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++;
> > }
> >  }
>
> > On Sat, Jun 4, 2011 at 2:29 PM, ross <[email protected]> wrote:
>
> >> Hi Rohit & all,
> >> Sorry that there was a small typo in the 'n' 'm' texts.
> >> The example given by me is anyway the correct one.
> >> Sravan Reddy's solution worked fine.
>
> >> On Jun 4, 10:08 am, rohit <[email protected]> wrote:
> >> > i think solution would be like this
>
> >> > eg:
> >> > A : 1 2 3 B: 0 1.5 4 5 9
> >> > Output:
> >> > A can contain any combination of nos 0,1,1.5
> >> > and B should contain 2 3 4 5 9 (in any order.)
>
> >> > this example is given by ROSS itself.
>
> >> > so sravanreddy solution is right , correct me if i'm wrong.
>
> >> > On Jun 3, 8:07 pm, bittu <[email protected]> wrote:
>
> >> > > @sravanreddy...logical bugs  if A is size of n & B is size m from your
> >> > > example  assuming n<m  so if you want smallest m elements in A then u
> >> > > only capacity of n elements & didn't allocate memory so these elements
> >> > > initialized by INT_MIN for m-n nodes so thatarrayA can hold m
> >> > > smallest elements then what r u swapping u dude..isn't garbage
> >> > > value ?? you will get at 1st step only just run it ?? in you algo
> >> > > A_End=m-1(which 4th position inArraythat DNE)..?? & also you have to
> >> > > free memory for  m-n  inarrayB as it contains n largest elements .
>
> >> > > take
> >> > > A= 1,2,3 n=3
> >> > > B= 0,1,4,5,9 m=5
>
> >> > > after allocating memory toArrayA  for  m-n elements A will looks
> >> > > likes 1 2 3 INT_Max INT_Max
> >> > > now what you wants A should contains m smallest elements & B have n
> >> > > largest elements
> >> > > so O/P should be  A=1,2,3,1,0 & B=INT_Max,INT_Max,4,5,9 now free
> >> > > memory used by 1st elements inarrayB so that A will represent M
> >> > > smallest elements & B will have n Largest elements
>
> >> > > so that above will work.
>
> >> > > Hope I am Correct let me know if any issue with explanation
>
> >> > > Thanks
> >> > > Shashank>>"The Best Way To Escape From Theproblemis To Solve It"
> >> > > CSE,BIT Mesra
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to [email protected].
> >> To unsubscribe from this group, send email to
> >> [email protected].
> >> For more options, visit this group at
> >>http://groups.google.com/group/algogeeks?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> -Aakash Johari
> (IIIT Allahabad)

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to