Company: SAP Labs_5sep
Difficulty: medium
Game Piece Movement Distance Problem Description You are given an array board of length N that describes consecutive positions on a game board, from left to right. Every position is either empty ( board[i] = 0 ) or holds a single game piece ( board[i] = 1 ). The pieces are moved according to these rules: Each game piece can be moved at most once . A move takes a piece one or more positions to the left or to the right. A piece moved by X positions travels distance X . A piece cannot capture another piece (end on a position that is occupied at that moment), and it cannot jump over another piece. Pieces can be moved in any order, but only one at a time. A piece must stay on the board, so every position stays within 0..N-1 . (inferred -- the source does not say so explicitly; there are no positions outside the board.) Find the maximum possible total distance that the game pieces can travel altogether. Complete the function solution(board) , which returns this maximum total distance. Input