Company: Texas_5aug
Difficulty: medium
ProcessArray Algorithm You are given an array arr of N integers. The array is repeatedly folded onto itself by the procedure below until only one element is left. One fold works like this: Step 1 — Split. Split the current array into a first half and a second half. If the current length is even, both halves have the same length. If the current length is odd, the first half gets one extra element: the first half takes the leading length / 2 + 1 elements (integer division) and the second half takes the remaining length / 2 elements. Step 2 — Scale the first half. Multiply every element of the first half by 2 . Step 3 — Scale the second half. Multiply every element of the second half by 3 . Step 4 — Merge. Add the two scaled halves element by element: the i -th element of the scaled first half is added to the i -th element of the scaled second half. When the current length is odd, the last element of the first half has no partner; it is carried over unchanged — that is, it keeps the value