Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Ruby/count_max_letter_in_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

# Name: Shoaib Sabir
# Username: Shoaib019
# Approach:
# Approach: take hash and initialize it with zero run loop over string
# increase count every time in hash key which is character
# then use max_by built in method to find letter with max count
def find_max_frequency_character(str)
arr = [nil, nil]
str.each_char_with_index do |ch, idx|
# do from here

hash = Hash.new(0)
str.each_char do |ch|
hash[ch] += 1
end
hash.max_by { |_, v| v }.first
end