Skip to content

2024-06-13 v. 5.8.8: added "2525. Categorize Box According to Criteria" #645

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
Jun 13, 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
@@ -448,3 +448,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 2511. Maximum Enemy Forts That Can Be Captured | [Link](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured/) | [Link](./lib/easy/2511_maximum_enemy_forts_that_can_be_captured.rb) |
| 2515. Shortest Distance to Target String in a Circular Array | [Link](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array/) | [Link](./lib/easy/2515_shortest_distance_to_target_string_in_a_circular_array.rb) |
| 2520. Count the Digits That Divide a Number | [Link](https://leetcode.com/problems/count-the-digits-that-divide-a-number/) | [Link](./lib/easy/2520_count_the_digits_that_divide_a_number.rb) |
| 2525. Categorize Box According to Criteria | [Link](https://leetcode.com/problems/categorize-box-according-to-criteria/) | [Link](./lib/easy/2525_categorize_box_according_to_criteria.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.8.7'
s.version = '5.8.8'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
s.executable = 'leetcode-ruby'
19 changes: 19 additions & 0 deletions lib/easy/2525_categorize_box_according_to_criteria.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

# https://leetcode.com/problems/categorize-box-according-to-criteria/
# @param {Integer} length
# @param {Integer} width
# @param {Integer} height
# @param {Integer} mass
# @return {String}
def categorize_box(length, width, height, mass)
volume = length * width * height
is_bulky = length >= 10.pow(4) || width >= 10.pow(4) || height >= 10.pow(4) || volume >= 10.pow(9)
is_heavy = mass >= 100

return 'Both' if is_bulky && is_heavy

return 'Neither' if !is_bulky && !is_heavy

is_bulky ? 'Bulky' : 'Heavy'
end
17 changes: 17 additions & 0 deletions test/easy/test_2525_categorize_box_according_to_criteria.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/easy/2525_categorize_box_according_to_criteria'
require 'minitest/autorun'

class CategorizeBoxAccordingToCriteriaTest < ::Minitest::Test
def test_default
assert_equal('Heavy', categorize_box(1000, 35, 700, 300))
assert_equal('Neither', categorize_box(200, 50, 800, 50))
end

def test_additional
assert_equal('Both', categorize_box(2909, 3968, 3272, 727))
assert_equal('Bulky', categorize_box(92_487, 6200, 58_423, 40))
end
end