Skip to the code
cf.
+10 XP

#672 Missing Frame Number

easy

A video player received frames numbered 0 to n, but one frame was dropped. frames holds the n frame numbers that arrived, in any order.

Write droppedFrame(frames) that returns the missing number, using O(1) extra memory.

Example 1

Input: frames = [3,0,1]
Output: 2

Frames 0 to 3 should all be there, and 2 is missing.

Example 2

Input: frames = [0,1]
Output: 2

The last frame, 2, is the one missing.

Constraints

  • 1 <= frames.length <= 10^5
  • The values are distinct and between 0 and frames.length.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).