FastPrepImplement memmove
Problems/Implement memmove

Implement memmove

NVIDIA logoNVIDIA● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a first-round interview for an NVIDIA AI infrastructure internship. One of the two coding tasks was to write memmove. The hints during the task were about source and destination ranges that overlap, and about the copy direction that this calls for.

The report gives no interface or limits. Here memory is an array of 1 to 1000 byte values from 0 to 255. You move n bytes from position src to position dest. Both ranges fit inside the array, and you return the whole array. The result must match a copy taken before any byte is written. Doing it with constant extra space is a follow-up.

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

Implement memmove on a small simulated block of memory. The array memory holds one byte value per position. Copy the n bytes that start at position src into the n positions that start at position dest, then return memory.

The two ranges may overlap. The result must be the same as if the n source bytes were first saved somewhere else and then written to the destination. Every position outside the destination range keeps its value.

Follow-up: can you do it without a second buffer, using only a constant amount of extra space?

Function

memmove(memory: int[], dest: int, src: int, n: int) → int[]

Examples

Example 1

memory = [1,2,3,4,5,6,7,8]dest = 2src = 0n = 4return = [1,2,1,2,3,4,7,8]

The source is positions 0 to 3, holding 1, 2, 3, 4. The destination is positions 2 to 5, so the two ranges overlap. After the move, positions 2 to 5 must hold 1, 2, 3, 4, and every other position keeps its value, so the result is [1,2,1,2,3,4,7,8]. Copying front to back would be wrong here: it would overwrite positions 2 and 3 before reading them and give [1,2,1,2,1,2,7,8].

Example 2

memory = [1,2,3,4,5,6,7,8]dest = 0src = 3n = 4return = [4,5,6,7,5,6,7,8]

The source is positions 3 to 6, holding 4, 5, 6, 7. They are written to positions 0 to 3. The ranges overlap at position 3. Positions 4 to 7 keep 5, 6, 7, 8, so the result is [4,5,6,7,5,6,7,8].

Example 3

memory = [9,8,7,6,5]dest = 3src = 0n = 2return = [9,8,7,9,8]

The source is positions 0 and 1, holding 9, 8. They are written to positions 3 and 4. The ranges do not overlap, so the result is [9,8,7,9,8].

Constraints

  • 1 <= memory.length <= 1000
  • 0 <= memory[i] <= 255
  • 0 <= n <= memory.length
  • 0 <= src and src + n <= memory.length
  • 0 <= dest and dest + n <= memory.length

More NVIDIA Phone Screen questions

  • Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
  • Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
  • Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
  • Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
  • Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
  • Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
  • Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
  • Merge Multiple Sorted StreamsPHONE SCREEN · Seen Aug 2026
  • Linked List Palindrome in Constant SpacePHONE SCREEN · Seen Aug 2026
  • LRU Key-Value Cache OperationsPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Compact Conversation History by Token BudgetSierra · PHONE SCREENSierra interview questions
  • Remove Duplicates from Sorted ArrayNykaa · PHONE SCREENNykaa interview questions
  • Minimum Index Distance Between Person and CakeSnowflake · OA · PHONE SCREENSnowflake interview questions
  • Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
  • Closest Vehicle and Charger in a LineSpotify · PHONE SCREEN
  • Correct an In-Place Array ReversalDuolingo · PHONE SCREENDuolingo interview questions
  • Remove Duplicates From Sorted Array In PlaceKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Merge Two Sorted ArraysCapgemini · PHONE SCREENCapgemini interview questions
  • Maximize Distance to the Closest Occupied SeatAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Remove Duplicates From Sorted Array In PlaceGet My Parking · PHONE SCREEN

Interview reports that mention this question

  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences

NVIDIA interview experiences

  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public int[] memmove(int[] memory, int dest, int src, int n) {
        // Write your code here.
    }
}
Checking account…