Skip to content

Latest commit

 

History

History
20 lines (14 loc) · 597 Bytes

smallest_unused_id.md

File metadata and controls

20 lines (14 loc) · 597 Bytes

Description

Hey awesome programmer!

You've got much data to manage and of course you use zero-based and non-negative ID's to make each data item unique!

Therefore you need a method, which returns the smallest unused ID for your next new data item...

Note: The given array of used IDs may be unsorted. For test reasons there may be duplicate IDs, but you don't have to find or remove them!

Go on and code some pure awesomeness!

My Solution

def next_id(arr)
  ((0..arr.size).to_a - arr).min
end