We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
// Please tell why error test cases go wrong on submit?
public static long largestRectangle(List h) {
int x = h.size() + 1;
Stack stack = new Stack<>();
Collections.sort(h);
for(int i = h.size() - 1; i >= 0; i--){
long a = (long) h.get(i) * (x - (i + 1));
stack.push(a);
}
long max = Long.MIN_VALUE;
// Iterate through the stack
while (!stack.isEmpty()) {
long num = stack.pop();
if (num > max) {
max = num;
}
}
return max;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Largest Rectangle
You are viewing a single comment's thread. Return to all comments →
// Please tell why error test cases go wrong on submit? public static long largestRectangle(List h) { int x = h.size() + 1; Stack stack = new Stack<>(); Collections.sort(h);
}