DSAMaster Logo
DSAMaster
BackmediumStrings

Minimum Transpositions to Palindrome

Problem Description

Given an array of integers arr, determine the minimum number of transposition operations required to transform it into a palindrome array. A transposition operation involves swapping two adjacent elements in the array.

Example 1
Input
[1, 3, 2, 1]
Output
1

Explanation: Swap 3 and 2 to get the palindrome [1, 2, 3, 1] requires only 1 transposition.

Example 2
Input
[1, 2, 3, 4, 5]
Output
2

Explanation: Transforming [1, 2, 3, 4, 5] to a palindrome [1, 5, 4, 3, 2] requires at least two transpositions.

Constraints

  • 1 <= arr.length <= 1000
  • -1000 <= arr[i] <= 1000
  • arr contains distinct integers
  • The transposition operation only swaps adjacent elements
  • The input array may or may not be a palindrome initially
00:00
Loading...

Sign in to Solve

Access the full code editor, ThinkBuddy AI hints, and track your progress.

Sign in Free
Test Cases & Output
Enter test input here...
Click "Run Code" to execute