Please read the new rule regarding the restriction on the use of AI tools. ×

abcuvw's blog

By abcuvw, history, 12 months ago, In English

I solved this problem using recursive memoization. Can anyone help me with iterative approach? Problem is as follows:

You are given an array A consisting of N numbers. In one move, you can either delete the first two, the last two or the first and last elements of A. No move can be performed if the length of array is less than 2. The result of each move is the sum of deleted elements. Find the maximum number of moves that can be performed such that all moves have same result.

Ex: A= [3,1,5,3,3,4,2] has max number of moves = 3 with result being 6 each time.

N<=1000 and A[i]<=1e9.

  • Vote: I like it
  • -38
  • Vote: I do not like it