How to use a 'two pointer' algorithm in Elixir

nums is a list, so Enum.at has an O(N) access time. Switching nums to a map:

faster_nums = 
  nums
  |> Enum.sort()
  |> Enum.with_index()
  |> Map.new(fn {value, index} -> {index, value} end) 

and using Map.get or the Access protocol:

faster_nums[a]    # instead of Enum.at(nums, a)

should do the trick, although that would be far from perfect. You can consider using Erlang’s array.