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.
Game of Two Stacks
Game of Two Stacks
Sort by
recency
|
411 Discussions
|
Please Login in order to post a comment
This question is very poorly described , and its misleading once you go from one stack to other you can't go back but its not mentioned properly
guys this is not a Greedy question where we can pick min of both the stacks. that doesn't work. We need to try all the possibilities. Recursion & Backtracking
Only 2 test cases (0,4)are passing all other are failing , can't think where is it going wrong public static int solve(Stack f,Stack s,int len , int cs,int max){ int n = f.peek()>=s.peek()?s.peek():f.peek(); // System.out.println(f.peek()); // System.out.println(s.peek()); // System.out.println("n:"+n); if(cs+n a, List b) { // Write your code here Stack first = new Stack<>(); for(int i =a.size()-1;i>=0;i--){ first.push(a.get(i)); } // System.out.println;
}