Find Missing Number

Find the missing number in a sequence from 1 to n using mathematical sum formula.

Code

Algorithms
n = arr.length + 1
return n * (n + 1) / 2 - arr.sum

Parameters

Array with one missing number

Server

More Ruby Snippets