Skip to content

2024-04-18 v. 5.4.9: added "2309. Greatest English Letter in Upper and Lower Case" #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2024
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -409,3 +409,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 2293. Min Max Game | [Link](https://leetcode.com/problems/min-max-game/) | [Link](./lib/easy/2293_min_max_game.rb) |
| 2299. Strong Password Checker II | [Link](https://leetcode.com/problems/strong-password-checker-ii/) | [Link](./lib/easy/2299_strong_password_checker_ii.rb) |
| 2303. Calculate Amount Paid in Taxes | [Link](https://leetcode.com/problems/calculate-amount-paid-in-taxes/) | [Link](./lib/easy/2303_calculate_amount_paid_in_taxes.rb) |
| 2309. Greatest English Letter in Upper and Lower Case | [Link](https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case/) | [Link](./lib/easy/2309_greatest_english_letter_in_upper_and_lower_case.rb) |
2 changes: 1 addition & 1 deletion leetcode-ruby.gemspec
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ require 'English'
::Gem::Specification.new do |s|
s.required_ruby_version = '>= 3.0'
s.name = 'leetcode-ruby'
s.version = '5.4.8'
s.version = '5.4.9'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
s.executable = 'leetcode-ruby'
23 changes: 23 additions & 0 deletions lib/easy/2309_greatest_english_letter_in_upper_and_lower_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

# https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case/
# @param {String} s
# @return {String}
def greatest_letter(s)
upper = {}
lower = {}

s.each_char do |c|
if c.match?(/[[:upper:]]/)
upper[c] = upper.fetch(c, 0) + 1
else
lower[c] = lower.fetch(c, 0) + 1
end
end

'ZYXWVUTSRQPONMLKJIHGFEDCBA'.each_char do |c|
return c if upper.fetch(c, 0).positive? && lower.fetch(c.downcase, 0).positive?
end

''
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/easy/2309_greatest_english_letter_in_upper_and_lower_case'
require 'minitest/autorun'

class GreatestEnglishLetterInUpperAndLowerCaseTest < ::Minitest::Test
def test_default
assert_equal('E', greatest_letter('lEeTcOdE'))
assert_equal('R', greatest_letter('arRAzFif'))
assert_equal('', greatest_letter('AbCdEfGhIjK'))
end
end