Skip to content

Commit 85ac0f0

Browse files
C editorial updated
1 parent 902b9a9 commit 85ac0f0

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed
Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# <center><u>[C. Decrease to Zero](https://www.hackerrank.com/contests/codecode-pec/challenges/decrease-to-zero)</u></center>
22
---
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$.
45

56
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.
67

@@ -11,10 +12,25 @@ Else, the player getting a number > 1 for the first time wins the game.
1112

1213
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.
1314

14-
For example consider the following cases
15-
Case 1: A = [3, 1, 1, 1, 4, 5] -> [0, 1, 1, 1, 4, 5] -> [0, 0, 1, 1, 4, 5] -> [0, 0, 0, 1, 4, 5] -> [0, 0, 0, 0, 4, 5] -> [0, 0, 0, 0, 1, 5] -> [0, 0, 0, 0, 0, 5] -> [0, 0, 0, 0, 0, 0]
16-
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.
1735

18-
Case 2: A = [3, 1, 1, 4, 5] -> [1, 1, 1, 4, 5] -> [0, 1, 1, 4, 5] -> [0, 0, 1, 4, 5] -> [0, 0, 0, 4, 5] -> [0, 0, 0, 1, 5] -> [0, 0, 0, 0, 5] -> [0, 0, 0, 0, 0]
19-
Again Alice wins, even though there were even number of 1's after $x$.
2036
</details>

0 commit comments

Comments
 (0)