Lets take an example I have an array a = [1,1,1,0,0] the arrangement of a which is [1,0,1,0,1] is giving the maximum sum of consecutive elements i.e, |1-0|+|0-1|+|1-0|+|0-1| = 4
The approach i used was pretty easy I rearranged the whole array by some algo. But if you look closely there is a pattern which depends on the number of elements in the array and the number of ones or zeros.
I'm already getting the solution , but if someone give me the pattern , that will be most fruitful.
Aucun commentaire:
Enregistrer un commentaire