We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

wait_to_get • 10 months ago

public class NearestGreaterToLeft {
public static void main(String[] args) {
int[] array = {9, 4, 15, 6, 2, 7, 10, 17, 5, 3};
int max = 0, near = 0;

for(int i : array) {
if(i > max)
max = i;

System.out.print(((i == max) ? -1 : (i <= near) ? near : max) + " ");
near = i;
}
}
}