FastPrepCustom Array Iterator
Problems/Custom Array Iterator

Custom Array Iterator

Nutanix logoNutanix● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report is a short account of a Nutanix software engineering intern interview in San Jose. The candidate had a one-hour technical interview after a short phone screen. Most of that hour, about 45 minutes, went to coding a class for a custom array iterator. The rest was about machine learning work on their resume.

The report does not say which methods the class needed or what it should do at the end of the array. Here the iterator has just two methods, next and hasNext. It walks an integer array from first to last, and next is never called after the last value. You get the calls as a list of operations instead of calling the class yourself. The array has up to 1000 values from -10^5 to 10^5. There are up to 2000 calls. The examples are ours.

Our version is about 70% the same as the reported question.

Implement a class ArrayIterator that walks through an integer array from the first value to the last:

  • ArrayIterator(int[] nums) creates the iterator. It starts before the first value of nums.
  • boolean hasNext() returns true if at least one value has not been returned yet, and false otherwise. It does not move the iterator.
  • int next() returns the next value and moves past it.

To test your class, you get the array nums and a list operations of calls made, in order, on one iterator built from nums. Each call is "next" or "hasNext". Return one string for each call, in the same order: the value from next in normal decimal form (such as "-3"), or "true" or "false" from hasNext.

Function

runArrayIterator(nums: int[], operations: String[]) → String[]

Examples

Example 1

nums = [8,-3,5]operations = ["hasNext","next","next","hasNext","next","hasNext"]return = ["true","8","-3","true","5","false"]

The iterator starts before 8. hasNext is "true". The two next calls return 8 and then -3. One value is still left, so hasNext is "true". The last next returns 5, and now nothing is left, so hasNext is "false".

Example 2

nums = []operations = ["hasNext","hasNext"]return = ["false","false"]

The array is empty, so there is never a next value. Both hasNext calls return "false".

Example 3

nums = [4,4]operations = ["next","hasNext","hasNext","next","hasNext"]return = ["4","true","true","4","false"]

next returns the first 4. The two hasNext calls in a row both return "true": asking does not move the iterator, so the second 4 is still waiting. The next next returns it, and then hasNext is "false".

Constraints

  • 0 <= nums.length <= 1000
  • -10^5 <= nums[i] <= 10^5
  • 1 <= operations.length <= 2000
  • Each operation is "next" or "hasNext".
  • next is only called when at least one value has not been returned yet.

More Nutanix Onsite Interview questions

  • Design Hit CounterONSITE INTERVIEW · Seen Oct 2026
  • Peak Process MemoryONSITE INTERVIEW · Seen Aug 2026
  • Minimum Operations to Transform ArrayONSITE INTERVIEW · Seen Jun 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
  • 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

  • Ring Buffer OperationsAmazon · ONSITE INTERVIEW
  • Apply Overridden Integer TransformsOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
  • Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Design an Ordered StreamBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Accumulate Numeric Value ObjectsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
  • Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • Round-Robin Iterator over IteratorsBridge · ONSITE INTERVIEWBridge interview questions
  • Top K Largest Values from a StreamThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Path Leaf Character IteratorGoogle · ONSITE INTERVIEWGoogle interview questions
  • Randomized Collection with Duplicate ValuesOkta · ONSITE INTERVIEWOkta interview questions

Interview reports that mention this question

  • Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)

Nutanix interview experiences

  • Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)
  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 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 String[] runArrayIterator(int[] nums, String[] operations) {
        // Write your code here.
    }
}
Checking account…