@Dheeraj

The ans for 14532 should be 15234..

I am calculating using the above given algo to get to the ans:

1) 4 is the value where A[i] < A[i+1] when scanned from the end.
2) The closest element grater than equal to 4 in the subarray 532 is
5.
3) Swap (4,5) : 14532 -> 15432
4) Now, as we have identified in step 1 the index of i, we need to
reverse the array from A[i+1, n] i.e. in 15(432) (432) needs to be
reversed and hence we will get 15234...

On Dec 11, 12:43 pm, Dheeraj Sharma <dheerajsharma1...@gmail.com>
wrote:
> @Lucifer..
>
> i thnk for 14532..ur ans wud be..21354..but it shu..21345..
> instread of reversing those..we have to sort them
>
>
>
>
>
>
>
>
>
> On Tue, Dec 6, 2011 at 4:13 PM, Lucifer <sourabhd2...@gmail.com> wrote:
> > @payel and anurag.. The algo that i have given is the same one that is
> > used by "next_permutation".. And yes, its returns the next higher
> > permutation.. In case ur input already points to the largest number
> > then it will return the smaller number...
> > On Dec 6, 12:38 pm, payel roy <smithpa...@gmail.com> wrote:
> > > @anurag, does the vector's next permutation return next higher
> > > element?
>
> > > On Dec 6, 8:10 am, Anurag Sharma <anuragvic...@gmail.com> wrote:
>
> > > > In context of C++
>
> > > >    1. Populate the digits of the given number in a vector V
> > > >    2. call next_permutation() on V
> > > >    3. print the vector [?]
>
> > > > Thanks,
> > > > Anurag Sharma
> > > > +91-8712218874
>
> > > > On Tue, Dec 6, 2011 at 2:23 AM, sourabh <sourabhd2...@gmail.com>
> > wrote:
> > > > > This problem is a direct implication of "next_permutation" defined
> > in C
> > > > > ++ STL algorithms.
>
> > > > > 1) From the end, keep decrementing till A[i] < A[i+1]..
> > > > > 2) Now, find the closest element , greater than equal, to A[i] in A[i
> > > > > +1 ... n]. Say, the index of the found element is "j".
> > > > > 3) Swap (A[i], A[j])
> > > > > 4) Reverse array A[i+1 .. n]
>
> > > > > On Dec 6, 12:37 am, Anup Ghatage <ghat...@gmail.com> wrote:
> > > > > > Hmm here is a thought.
>
> > > > > > In the given number, check the second digit from the left.
>
> > > > > > if it is the maximum, find the digit that is the next greater
> > digit from
> > > > > > the left most digit.
> > > > > > append it to the start and append all the other numbers in sorted
> > order.
>
> > > > > > if the second from left isn't the largest, find the next digit
> > that is
> > > > > > greater than the last digit and swap places with it.
>
> > > > > > On Mon, Dec 5, 2011 at 11:05 PM, raushan kumar <
> > > > > raushan.vns2...@gmail.com>wrote:
>
> > > > > > > Given a number,find the next higher number using the same digits
> > in the
> > > > > > > number.
> > > > > > > eg: 15432  :: 21345
> > > > > > >        14532
>
> > > > > > > --
> > > > > > > You received this message because you are subscribed to the
> > Google
> > > > > Groups
> > > > > > > "Algorithm Geeks" group.
> > > > > > > To post to this group, send email to algogeeks@googlegroups.com.
> > > > > > > To unsubscribe from this group, send email to
> > > > > > > algogeeks+unsubscr...@googlegroups.com.
> > > > > > > For more options, visit this group at
> > > > > > >http://groups.google.com/group/algogeeks?hl=en.
>
> > > > > > --
> > > > > > Anup Ghatage
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > Groups
> > > > > "Algorithm Geeks" group.
> > > > > To post to this group, send email to algogeeks@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > algogeeks+unsubscr...@googlegroups.com.
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/algogeeks?hl=en.
>
> > > >  330.gif
> > > > < 1KViewDownload- Hide quoted text -
>
> > > > - Show quoted text -
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> *Dheeraj Sharma*

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

Reply via email to