is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
You can solve it in O(n) time and O(n) space by using the BST property.
- creativeengineer2016 February 21, 2017static Stack<Range> stack = new Stack<>();
static class Range{
int min;
int max;
Range(int min, int max){
this.min = min;
this.max = max;
}
}
public static List<Integer> findLeaves(int[] pre){
List<Integer> leaves = new ArrayList<>();
if(pre == null || pre.length == 0)
return leaves;
stack.push(new Range(Integer.MIN_VALUE, Integer.MAX_VALUE));
for(int i=0; i<pre.length; i++){
Range curr = stack.pop();
//confirm in the range
if(curr.min < pre[i] && pre[i] < curr.max){
pushRightLeftToStack(curr, pre[i]);
}
else{
Range next = stack.pop();
if(next.min < pre[i] && pre[i] < next.max){
pushRightLeftToStack(next, pre[i]);
}
else{
leaves.add(next.min); //dont forget to add this leaf
leaves.add(pre[i]);
}
}
}
return leaves;
}
private static void pushRightLeftToStack(Range r, int val){
Range right = new Range(val, r.max);
Range left = new Range(r.min, val);
stack.push(right);
stack.push(left);
}