Sorted Absolute-Difference Sums Across Cyclic Shifts
Updated
Problem statement
Given two integer arrays nums1 and nums2 of equal length n, consider every cyclic right shift of nums1.
For a shift of s positions, the value compared with nums2[i] is nums1[(i - s + n) % n]. Compute the sum of absolute pairwise differences for each shift s from 0 through n - 1.
Return all n sums sorted in nondecreasing order. Use 64-bit arithmetic for the differences and sums.
Function
sortedCyclicShiftDifferences(nums1: int[], nums2: int[]) → long[]Examples
Example 1
nums1 = [1, 4, 2, 11]nums2 = [10, 1, 8, 4]return = [7, 13, 25, 25]The four right shifts produce difference sums 25, 25, 13, and 7. Sorting them gives the returned array.
Example 2
nums1 = [1, 2]nums2 = [2, 1]return = [0, 2]Without shifting, the sum is 2. Shifting right once produces [2, 1], whose sum is 0.
Constraints
1 <= nums1.length == nums2.length <= 200-10^9 <= nums1[i], nums2[i] <= 10^9
More ByteDance interview questions
- Count House Segments After Sequential DestructionOA · Seen Aug 2026
- Count Numbers with an Even Digit CountOA · Seen Aug 2026
- Sort Concentric Matrix Borders ClockwiseOA · Seen Aug 2026
- Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
- Log Analyzer: Busiest Service in a Rolling WindowPHONE SCREEN · Seen Nov 2026
- Search a Row- and Column-Sorted MatrixONSITE INTERVIEW · Seen Nov 2026
- Majority ElementPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- Binary Tree Target-Sum PathsPHONE SCREEN · Seen Nov 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Nov 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
- Sorted Cyclic Shift Difference SumsCapital One · OACapital One interview questions
- Optimize Package Order by Sorting One WindowAmazon · OA
- Track Received Byte RangesRoblox · OARoblox 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
ByteDance interview experiences
- ByteDance TikTok USDS SWE Intern Interview: 1 Experience
- ByteDance MLE New Grad Interviews: 1 Experience
- ByteDance Security SRE Intern Phone Screens: 1 Experience
- ByteDance USDS New Grad SWE Phone Screen: 1 Experience
- ByteDance New Grad Data Engineer Video Interviews: 1 Experience
- ByteDance Trust & Safety Research Scientist Intern: 1 Experience