Sorted Cyclic Shift Difference Sums
Updated
Problem statement
Given two integer arrays nums1 and nums2 of equal length, consider every cyclic right shift of nums1. For shift s, the value aligned with index i is nums1[(i - s + n) % n].
For every shift, compute the sum of absolute differences between aligned values from the shifted nums1 and nums2. Return all n sums sorted in nondecreasing order.
Function
sortedCyclicShiftDifferences(nums1: int[], nums2: int[]) → long[]Examples
Example 1
nums1 = [1,2,3]nums2 = [2,1,3]return = [2,2,4]The right shifts are [1,2,3], [3,1,2], and [2,3,1], with difference sums 2, 2, and 4.
Example 2
nums1 = [5]nums2 = [-2]return = [7]A one-element array has only one cyclic shift.
Example 3
nums1 = [0,10]nums2 = [10,0]return = [0,20]The unshifted alignment costs 20, while shifting right once makes the arrays equal.
Constraints
1 <= nums1.length = nums2.length <= 500.-10^9 <= nums1[i], nums2[i] <= 10^9.- Use 64-bit arithmetic for every sum.
More Capital One Online Assessment questions
- Rank Football TeamsOA · Seen Oct 2026
- Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
- Arithmetic Triplets After QueriesOA · Seen Oct 2026
- Branch with the Most FilesOA · Seen Oct 2026
- Count One-Swap Number PairsOA · Seen Oct 2026
- Distinct Values on Maximum-Sum FramesOA · Seen Oct 2026
- Earliest Meeting Time for All EmployeesOA · Seen Oct 2026
- Earn the Most 🐝OA · Seen Oct 2026
- Sort Adjacent PairsOA · Seen Oct 2026
- Bouncing Diagonal WeightsOA · Seen Oct 2026
Similar questions at other companies
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
- Macaron Order PriceOpenAI · OAOpenAI interview questions
- Optimize Package Order by Sorting One WindowAmazon · OA
- Track Received Byte RangesRoblox · OARoblox interview questions
- Sorted Absolute-Difference Sums Across Cyclic ShiftsByteDance · OAByteDance interview questions
- Signal PingsVisa · OAVisa interview questions
- Aggregate Paginated Project Run RecordsReplit · OA
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Parcel Attribute Store with TTLAirbnb · OAAirbnb interview questions