Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
Created April 18, 2015 20:20
Show Gist options
  • Save stephen-maina/dfb510b37dd85a598655 to your computer and use it in GitHub Desktop.
Save stephen-maina/dfb510b37dd85a598655 to your computer and use it in GitHub Desktop.
had to research to get the full 100
import java.util.Stack;
class Solution {
public int solution(int[] A, int[] B) {
// write your code in Java SE 8
Stack<Integer> upStack=new Stack<Integer>();
Stack<Integer> downStack=new Stack<Integer>();
for(int index=0;index<A.length;index++){
if(B[index]==0){
while(!downStack.empty()&&downStack.peek()<A[index]){
downStack.pop();
}
if(downStack.empty()){
upStack.push(A[index]) ;
}
}else{
downStack.push(A[index]);
}
}
return upStack.size()+downStack.size();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment