Elixir Missing Integer
defmodule MissingInteger do
def missing_integer(a) do
sorted = a |> Enum.uniq() |> Enum.sort()
Enum.reduce_while(sorted, 1, fn v, min ->
cond do
v <= 0 -> {:cont, min}
min != v -> {:halt, min}
true -> {:cont, min + 1}
end
end)
end
end
This records the positive numbers that exist, then returns the smallest positive value that is still missing.