Minimum Difference Across Cyclic Rotations
Problem statement
You are given equal-length integer arrays first and second. For every cyclic left rotation of first, sum the absolute differences of aligned elements.
Return the minimum sum across all rotations.
Function
minimumRotationDifference(first: int[], second: int[]) → longExamples
Example 1
first = [1,2,3]second = [2,3,1]return = 0One left rotation makes the arrays equal.
Example 2
first = [1,4]second = [2,8]return = 5The unrotated cost is 1 + 4 = 5, which is minimal.
Constraints
1 <= first.length == second.length <= 2000-1000000000 <= value <= 1000000000