diff --git a/README.md b/README.md index 4182dafc..6e5f4312 100644 --- a/README.md +++ b/README.md @@ -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) | diff --git a/leetcode-ruby.gemspec b/leetcode-ruby.gemspec index 6cbad724..a8e57256 100644 --- a/leetcode-ruby.gemspec +++ b/leetcode-ruby.gemspec @@ -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' diff --git a/lib/easy/2525_categorize_box_according_to_criteria.rb b/lib/easy/2525_categorize_box_according_to_criteria.rb new file mode 100644 index 00000000..a0517b3c --- /dev/null +++ b/lib/easy/2525_categorize_box_according_to_criteria.rb @@ -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 diff --git a/test/easy/test_2525_categorize_box_according_to_criteria.rb b/test/easy/test_2525_categorize_box_according_to_criteria.rb new file mode 100644 index 00000000..3bc8644b --- /dev/null +++ b/test/easy/test_2525_categorize_box_according_to_criteria.rb @@ -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