https://programmers.co.kr/learn/courses/30/lessons/42588#
import java.util.*;
class Solution {
public int[] solution(int[] heights) {
int[] answer = new int[heights.length];
Stack<Integer> tower = new Stack<Integer>();
for(int i=heights.length-1; i>=0; i--) {
tower.push(heights[i]);
}
for(int i=0; i<heights.length; i++) {
int k = tower.pop();
if(i==0)
answer[i]=0;
else {
for(int j=i-1; j>=0; j--) {
if(heights[j]>k){
answer[i]=j+1;
break;
}
}
}
}
return answer;
}
}