FastPrepMinimum Operations to Transform Array
Problems/Minimum Operations to Transform Array

Minimum Operations to Transform Array

Nutanix logoNutanix● MediumFULLTIMEONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given two integer arrays:

  • a with length n
  • b with length n + 1

You may perform the following operations on a:

  • Increment any element by 1.
  • Decrement any element by 1.
  • Copy any current element of a and append the copy to the end of a.

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[]) → long

Examples

Example 1

a = [1]b = [2,3]return = 3

Increment 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 = 1

Copy 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 = 8

The 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

  • a and b are integer arrays.
  • a has length n, and b has length n + 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
All Nutanix interview questionsSee Nutanix hiring insights
Saved
class Solution {
    public long minimumOperationsToTransformArray(int[] a, int[] b) {
      // write your code here
    }
}
Checking account…