Approach #1: Direct [Accepted]

Intuition and Algorithm

We can do this in place. In each row, the ith value from the left is equal to the inverse of the ith value from the right.

We use (C+1) / 2 (with floor division) to iterate over all indexes i in the first half of the row, including the center.

Complexity Analysis

  • Time Complexity: , where N is the total number of elements in A.

  • Space Complexity: in additional space complexity.


Analysis written by: @awice.