zack.kenyon
BAN USER@Ramesh I agree that the input and output you listed convey what you mean. just that, there is a formal statement of the question which is precise and accurate, and not at all complex.
the next largest element in english would most commonly mean the least element in the array with is larger than it, whereas the "next, largER element" would probably be closer.
1 object will be created, which you can easily verify by testing the code for object equality.
String temp="A"+"B"+"C";
if (temp == "ABC" && temp == "A"+"B"+"C"){
System.out.println("QED");
}
The question is asking to replace each element with the next element in the list which is larger than it.
Which is not at all clear from the phrase "Next Largest Element".
stack = Stack.new
stack.push(ary[len(ary)-1])
for i in range(len(ary)-2,0,-1):
while(ary[i]>stack.peek()):
stack.pop()
if(stack.peek()>ary[i]):
ary[i]=stack.peek()
stack.push(ary[i])
sum=0
while(true){
b=stream.next()
a=1<<b
a & sum? return b:sum+=a
}
sum=0
while(true){
b=stream.next()
a=2**b
a & sum? return b:sum+=a
}
or the (n+1)th Fibonacci number, depending on what you consider the sequence to be.
- zack.kenyon March 03, 2014Interesting side note. (n+1)th is the only "word" that rhymes with month.