Given an array and return the minimum number of operation (+,-) to make all values equal . In one move , you can subtract/add to the current value and its adjacent values . If no possible moves exist , return -1 ex:
1 0 5
1St move: 1 0<--5 => 1 1 4
2nd move: 1<--1<--4 => 2 1 3
3rd move: 2 1<--3 => 2 2 2
0 2 0
ans : -1 (not possible to make all equal)
I have tried to google and build approach , but could not
Aucun commentaire:
Enregistrer un commentaire