[Community Puzzle] Equalizing arrays

Hi there,

I am quite stuck on this one. I implemented some very simple code which gets me a score of 55%.
I don’t know how to get all possible answers, and first of all I don’t even know if it is really needed to compute all the solutions, only several optimal solutions, or if the best solution can be calculated with one pass.
I don’t know were to start to reach the 100%.
Should I go brute force, recursive… ?

Any help/hint will be greatly appreciated

1 Like

link ??? :d

https://www.codingame.com/training/medium/equalizing-arrays

2 Likes

The sorting order at the end makes no sense to me. The author gives a way to sort sequences of operations, but not how to sort operations within the sequences, something he clearly does.
On puzzle 10 for example, there is simply one giant sequence of operations that goes right to left (index 80 down to 1), yet the expected output is not in that order, go figure.
My guess : the author wrote a solution that gave him a specific order and then simply asked everybody else to match his output, whatever it is (I could be wrong but right now I’m a bit pissed if you can’t tell).

The actual order of operations :

80 -1 100000
79 -1 95794
78 -1 84510
77 -1 33955
76 -1 133955
75 -1 119652
74 -1 97582
73 -1 47294
72 -1 147294
71 -1 106839
70 -1 72811
69 -1 22294
68 -1 122294
67 -1 116898
66 -1 111148
65 -1 61503
64 -1 161503
63 -1 152416
62 -1 145183
61 -1 94442
60 -1 194442
59 -1 161630
58 -1 155899
57 -1 105555
56 -1 205555
55 -1 165979
54 -1 139060
53 -1 88390
52 -1 188390
51 -1 163579
50 -1 127815
49 -1 77961
48 -1 177961
47 -1 133050
46 -1 119013
45 -1 68390
44 -1 168390
43 -1 122114
42 -1 83754
41 -1 33503
40 -1 133503
39 -1 119061
38 -1 81507
37 -1 31352
36 -1 131352
35 -1 89003
34 -1 77903
33 -1 27382
32 -1 127382
31 -1 93897
30 -1 75911
29 -1 25734
28 -1 125734
27 -1 101265
26 -1 66107
25 -1 15765
24 -1 115765
23 -1 105285
22 -1 66851
21 -1 16081
20 -1 116081
19 -1 112267
18 -1 70406
17 -1 19823
16 -1 119823
15 -1 95310
14 -1 74464
13 -1 24036
12 -1 124036
11 -1 120671
10 -1 76057
9 -1 25722
8 -1 125722
7 -1 97542
6 -1 58227
5 -1 7771
4 -1 107771
3 -1 66572
2 -1 50101

The expected output :

5 -1 7771
4 -1 107771
3 -1 66572
2 -1 50101
9 -1 25722
8 -1 125722
7 -1 97542
6 -1 58227
13 -1 24036
12 -1 124036
11 -1 120671
10 -1 76057
17 -1 19823
16 -1 119823
15 -1 95310
14 -1 74464
21 -1 16081
20 -1 116081
19 -1 112267
18 -1 70406
25 -1 15765
24 -1 115765
23 -1 105285
22 -1 66851
29 -1 25734
28 -1 125734
27 -1 101265
26 -1 66107
33 -1 27382
32 -1 127382
31 -1 93897
30 -1 75911
37 -1 31352
36 -1 131352
35 -1 89003
34 -1 77903
41 -1 33503
40 -1 133503
39 -1 119061
38 -1 81507
69 -1 22294
68 -1 122294
67 -1 116898
66 -1 111148
65 -1 61503
64 -1 161503
63 -1 152416
62 -1 145183
61 -1 94442
60 -1 194442
59 -1 161630
58 -1 155899
57 -1 105555
56 -1 205555
55 -1 165979
54 -1 139060
53 -1 88390
52 -1 188390
51 -1 163579
50 -1 127815
49 -1 77961
48 -1 177961
47 -1 133050
46 -1 119013
45 -1 68390
44 -1 168390
43 -1 122114
42 -1 83754
73 -1 47294
72 -1 147294
71 -1 106839
70 -1 72811
77 -1 33955
76 -1 133955
75 -1 119652
74 -1 97582
80 -1 100000
79 -1 95794
78 -1 84510
1 Like

The author knows that there may be multiple solutions.
It is not possible to set all possible solutions and check if the output is right.

So he set an additional rule :

If there are several orders of operations possible then output the one that is lexicographically minimal.

So you have two option :

  • find all solutions and choose the good one
  • find the solution doing the operations in the good order from the start
1 Like

Ok I’ll check for multiple solutions and see.

Edit : solved, there is indeed a way that naturally gives you the right ordering with multiple solutions. So my point still stands, the author did his thing and told us to match his algorithm :slight_smile:

Hi,
I’ve managed to pass all tests (it was hard to find a way to have the operations in the right order but i’ve found a way…), but the validators 5 (Random) and 10 (Blocks) don’t pass …
I’m stuck; it’s hard to tell what is wrong
Can anyone give me hints, or give other test values to try to figure out the problem ?

Hi,
probably not worth mentioning anymore, but I just had the same problem. Probably you missed to pass overflow to the right after you passed it to the left. At least that was what it took to light up green for me.
Cheers