Learning idiomatic Elixir - Q1

This solution reminds me of how imperative languages may approach the problem–by maintaining “pointers” or indices within the array. It seems you found the most elegant solution to the problem. It is clever to use pattern matching as the “pointer” effectively, thanks for sharing your solution :slight_smile:

One could entertain converting the list into a map list |> Enum.with_index |> Map.new to mimic pointers with two indices, one for the start of the window and one for the end.

Though looking at the Big O for map access the solution would be O(n * log n) in that case, so it won’t work. I also think the code would be more verbose going down this path.

1 Like