@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
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
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
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: