Skip to content

Instantly share code, notes, and snippets.

@enderahmetyurt
Created June 30, 2025 10:20
Show Gist options
  • Save enderahmetyurt/2d3c6bae5dd621c839b97bbfa2de73f8 to your computer and use it in GitHub Desktop.
Save enderahmetyurt/2d3c6bae5dd621c839b97bbfa2de73f8 to your computer and use it in GitHub Desktop.
Find the last non-repeating character in a given string.
def non_repeat(str)
counts = Hash.new(0)
str.each_char { |char| counts[char] += 1 }
str.reverse.each_char do |char|
return char if counts[char] == 1
end
""
end
puts non_repeat('candy canes do taste yummy')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment