PROBLEM LINK:Author: Bhuvnesh Jain Tester: Ankit Sultana Editorialist: Bhuvnesh Jain DIFFICULTY:CAKEWALK PREREQUISITES:Basic Looping techniques PROBLEM:Find any valid sequence of magic operations so that all the cards face upwards. EXPLANATION:The only observation for this problem required is that the magic operation on the rightmost card affects only itself and not any other card. So, we simply do a linear scan from left to right and whenever we encounter a card facing down, we perform the magic operation on it. This solution will tak atmost $O(n)$ steps as we can perform the magic operation on all the elements in the worst case. As per the constraints, $k >= n$, so the above solution will work. COMPLEXITY$O(n)$ Solution codes:asked 27 Mar '17, 00:05

We must do binary search in this question by comparing each element with its consecutive element.We must not do anything if its a positive no. but if its a negative no. there will be two cases
link
This answer is marked "community wiki".
answered 27 Mar '17, 00:46
