Minimum Operations to Transform Array
Updated
Problem statement
You are given two integer arrays:
awith lengthnbwith lengthn + 1
You may perform the following operations on a:
- Increment any element by
1. - Decrement any element by
1. - Copy any current element of
aand append the copy to the end ofa.
After all operations, the first n positions of a must equal the first n positions of b, and the appended element must equal b[n].
Return the minimum number of operations required.
Function
minimumOperationsToTransformArray(a: int[], b: int[]) → longExamples
Example 1
a = [1]b = [2,3]return = 3Increment 1 to 2, copy the value, then increment the copied value to 3. This takes 3 operations.
Example 2
a = [3,3,3]b = [3,3,3,3]return = 1Copy any existing 3 and append it to the end.
Example 3
a = [5,2,1,4,6]b = [4,1,5,4,6,7]return = 8The first five positions require 6 total increment/decrement operations. Copying a value costs 1; the best copied value can be adjusted to 7 with one additional operation, for a total of 8.
Constraints
aandbare integer arrays.ahas lengthn, andbhas lengthn + 1.
More Nutanix Onsite Interview questions
- Design Hit CounterONSITE INTERVIEW · Seen Oct 2026
- Peak Process MemoryONSITE INTERVIEW · Seen Aug 2026
- Count Connected Components in an Undirected GraphONSITE INTERVIEW · Seen Aug 2025
- LRU CacheONSITE INTERVIEW · Seen Aug 2025
- Running Median of a Multilevel Linked List in Level OrderONSITE INTERVIEW · Seen Aug 2025
- Custom Array IteratorONSITE INTERVIEW · Seen Dec 2024
- Collapse Runs of Repeated CharactersONSITE INTERVIEW · Seen Nov 2022
- Anagram Words in a SentenceONSITE INTERVIEW · Seen Apr 2022
- Sudoku SolverONSITE INTERVIEW · Seen Feb 2022
- Distance Sums to Special Nodes in a Weighted TreeONSITE INTERVIEW · Seen Aug 2021
Similar questions at other companies
- Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
- Best Time to Buy and Sell Stock IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Minimize Total Weight After HalvingAmazon · ONSITE INTERVIEW
- Capacity to Ship Packages Within DaysMicrosoft · OA · ONSITE INTERVIEWMicrosoft interview questions
- Gas StationeBay · ONSITE INTERVIEWeBay interview questions
- Make an Array Non-Decreasing With One ModificationGoogle · ONSITE INTERVIEWGoogle interview questions
- Wizard Scroll Allocation StrategyJane Street · ONSITE INTERVIEWJane Street interview questions
- Maximize Compatible Car RidersUber Freight · PHONE SCREEN · ONSITE INTERVIEWUber Freight interview questions
Nutanix interview experiences
- Nutanix interviews · November 2026
- Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)
- Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
- Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
- Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
- Nutanix Intern Debugging Round and Interviews: 25 Experiences