Created
April 18, 2015 20:20
-
-
Save stephen-maina/dfb510b37dd85a598655 to your computer and use it in GitHub Desktop.
had to research to get the full 100
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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