Re: [algogeeks] Next higher element

2010-06-24 Thread Raj N
@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.comalgogeeks%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.comalgogeeks%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.



Re: [algogeeks] Next higher element

2010-06-24 Thread chitta koushik
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.comalgogeeks%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.comalgogeeks%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.comalgogeeks%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.



Re: [algogeeks] Next higher element

2010-06-23 Thread Kumar Vishal
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.comalgogeeks%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.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.