@Chitta: Hey this doesn't work in all cases. For eg: 4 1 3 5 6
Output:
4-5
1-3
3-5
5-6
6-null

But according to ur logic u push 4 then, u push 1 as it is < 4, do u
conclude that 4 doesn't have next higher element ?

On Thu, Jun 24, 2010 at 4:04 PM, chitta koushik
<koushik.infin...@gmail.com>wrote:

> push the elements into stack , when the element to be pushed is greater
> than the 'top' element.. pop the elements and write then
>
> eg : if array is 1 2 3 4 5 8 6
>
> insert 1
> -----
> stack : 1
>
> insert 2 ( as 2 > top i.e 1)
> -----
>  output  1 - 2
> stack : 2
>
> insert 3 ( as 3 > top i.e 2)
> -----
> output  1-2, 2-3
> stack 3
>
> .
> .
> .
> insert 8 ( as 8 > top i.e 5)
> ------
> output  1-2, 2-3,3-4,4-5
> stack 8
>
> insert 6
> -----------
> output 1-2, 2-3,3-4,4-5,5-8
> stack 8,6
>
>
> final output : 1-2, 2-3,3-4,4-5,5-8,8- -1 , 6 - -1
>
>
>
>
>
>
>
>
> On Wed, Jun 23, 2010 at 10:48 PM, Raj N <rajn...@gmail.com> wrote:
>
>> @Kumar: The next higher of 5 will be 7 as it comes first in the array.
>>
>>
>> On Wed, Jun 23, 2010 at 5:28 PM, Kumar Vishal <kumar...@gmail.com> wrote:
>>
>>> hi the number should be just next higher element or any higher element
>>>
>>> like
>>> if my arr is like
>>>
>>> arr= 2 5 1 3 7 6
>>>  the next higher element for 5
>>>  should be what (7 or 6 )  because 6 is more closer to 7 but 7 comes
>>> first in arr
>>>
>>>
>>> On Wed, Jun 23, 2010 at 11:18 AM, Raj N <rajn...@gmail.com> wrote:
>>>
>>>> Design a data structure to find the next higher element for each
>>>> element in an array.
>>>> For e.g. if array is 1 2 3 4 5 8 6
>>>> o/p should be
>>>> (element) (next higher element)
>>>> 1 2
>>>> 2 3
>>>> 3 4
>>>> 4 5
>>>> 5 8
>>>> 8 nothing
>>>> 6 nothing
>>>>
>>>> The array need not be sorted.
>>>> Constraints-O(n) time complexity
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algoge...@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>>
>>>
>>>
>>> --
>>> Kumar Vishal
>>> ____________________________
>>> StAy HunGrY , StAy fOOlisH
>>> ____________________________
>>> Contact No:- 09560193839
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>>> .
>>> 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 algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> 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 algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> 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 algoge...@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