Thursday, April 14, 2011

Next smaller in array

For each number, find the next smaller number in the array. If next smaller number does not exists, put 0.
Eg.
Input:   1  5 7 6 3 1  6  2  9  2 7
Output: 0 3  6 3 1 0  2  0  2  0 0

No comments: