Transform an Array with One Copy
Updated
Problem statement
Arrays a and b have lengths n and n+1. In one operation you may increase any current a element by one, decrease one by one, or copy any current a element and append that copy to the end. Return the minimum operations needed to make a equal b in order.
The newly appended element can also be increased or decreased. Exactly one append is necessary because the final length increases by one. Every intermediate value may be any integer.
Function
minimumOperations(a: int[], b: int[]) → longExamples
Example 1
a = [2]b = [1,3]return = 3Copy 2, decrease the original to 1, and increase the copy to 3.
Example 2
a = [4,2,1,2]b = [2,1,5,2,3]return = 8Copy a value 3 while the first element moves from 4 to 2; the four original positions need seven edits in total.
Constraints
- 1 <= n <= 200000 and 1 <= a[i], b[i] <= 10^9. Return a signed 64-bit count.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Minimum Cost to Merge Values into OnePayPal · OAPayPal interview questions
- Minimum Operations to Sort with Rotations Then SwapsBank of New York Mellon · OA
- Minimum Cost of Left and Right PropagationAmazon · OA
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Reschedule Meetings for Maximum Free TimeFivetran · OAFivetran interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Maximum ScoreNVIDIA · OANVIDIA interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
- Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions