We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Post 37
Hacker Rank 11 - Remove Duplicates
Published on: 2025-06-09
Tags:
elixir, Side Project, Hacker Rank
This was one of the easiest ones that I did. I knew from the beginning I new that a reduce and String.graphemes was the way to go.
Once you have the string I implemented this.
def remove_duplicates(string) do
string
|> String.graphemes()
|> Enum.reduce([], fn character, list ->
if character in list, do: list,
else: [character | list]
end)
|> Enum.reverse()
end
Take the string and turn it into a list, reduce over the list and prepend the character to the list if not in the accumulator, reverse the list.
That is about it... really.