You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# <center><u>[C. Decrease to Zero](https://www.hackerrank.com/contests/codecode-pec/challenges/decrease-to-zero)</u></center>
2
2
---
3
-
The condition $0 < X*A_i ≤ A_i^2$ implies that X can have any integer value from 0 to $abs(A_i)$ and its sign will be the same as the sign of $A_i$.
3
+
4
+
The condition $0 < x*A_i ≤ A_i^2$ implies that $x$ can have any integer value from 0 to $|A_i|$ and its sign will be the same as the sign of $A_i$. In other words the sign of $A_i$ can be ignored and you can replace $A_i$ with $|A_i|$ for every $i$.
4
5
5
6
Now, if the array only contains 1's, then every time the player will choose it and make it zero. So, the answer will be dependent on the parity of n.
6
7
@@ -11,10 +12,25 @@ Else, the player getting a number > 1 for the first time wins the game.
11
12
12
13
Suppose, a player gets a number $x$ on his/her turn such that $x > 1$. Then, the player can make it either 1 or 0 to confirm his/her win.
So, the above sequence of operation shows that Alice wins when there are an odd number of 1's after $x$
15
+
`For Example` consider the following cases
16
+
Case 1: $A = [3, 1, 1, 1, 4, 5]$
17
+
* $[0, 1, 1, 1, 4, 5]$ Alice picks 3
18
+
* $[0, 0, 1, 1, 4, 5]$ Bob is forced to pick 1
19
+
* $[0, 0, 0, 1, 4, 5]$ Alice picks 1
20
+
* $[0, 0, 0, 0, 4, 5]$ Bob is forced to pick 1
21
+
* $[0, 0, 0, 0, 1, 5]$ Alice reaches a number with value $> 1$ again.
22
+
<!-- * $[0, 0, 0, 0, 0, 5]$ Bob is forced to pick 1
23
+
* $[0, 0, 0, 0, 0, 0]$ Alice winds by picking 5 -->
24
+
25
+
So, the above sequence of operation shows that Alice can always find some set of moves that results her to jump from a number $> 1$ to another number $> 1$ by skipping odd number of $1s$.
26
+
27
+
Case 2: $A = [3, 1, 1, 4, 5]$
28
+
* $[1, 1, 1, 4, 5]$ Alice picks 2
29
+
* $[0, 1, 1, 4, 5]$ Bob is forced to pick 1
30
+
* $[0, 0, 1, 4, 5]$ Alice picks 1
31
+
* $[0, 0, 0, 4, 5]$ Bob is forced to pick 1
32
+
* $[0, 0, 0, 1, 5]$ Alice reaches a number with value $> 1$ again.
33
+
34
+
Therefore, if there are even number of $1s$ between 2 numbers (both $> 1$) then the player can always find a way to jump from 1 to the other.
0 commit comments