build a prefix array cpp

To build a prefix array in C++, follow these steps:

  1. Initialize a prefix array of the same size as the input array.
  2. Set the first element of the prefix array to the first element of the input array.
  3. Iterate through the input array starting from the second element.
  4. For each element at index i, set the prefix array at index i to the sum of the current input array element and the previous prefix array element.
  5. The resulting prefix array contains the cumulative sum of the input array elements up to each index.