Skip to content

Commit 3484704

Browse files
authored
Merge pull request #645 from fartem/2525_Categorize_Box_According_to_Criteria
2024-06-13 v. 5.8.8: added "2525. Categorize Box According to Criteria"
2 parents 6a2c7cc + 5076025 commit 3484704

4 files changed

+38
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
448448
| 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) |
449449
| 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) |
450450
| 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) |
451+
| 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) |

leetcode-ruby.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'English'
55
::Gem::Specification.new do |s|
66
s.required_ruby_version = '>= 3.0'
77
s.name = 'leetcode-ruby'
8-
s.version = '5.8.7'
8+
s.version = '5.8.8'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
1111
s.executable = 'leetcode-ruby'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/categorize-box-according-to-criteria/
4+
# @param {Integer} length
5+
# @param {Integer} width
6+
# @param {Integer} height
7+
# @param {Integer} mass
8+
# @return {String}
9+
def categorize_box(length, width, height, mass)
10+
volume = length * width * height
11+
is_bulky = length >= 10.pow(4) || width >= 10.pow(4) || height >= 10.pow(4) || volume >= 10.pow(9)
12+
is_heavy = mass >= 100
13+
14+
return 'Both' if is_bulky && is_heavy
15+
16+
return 'Neither' if !is_bulky && !is_heavy
17+
18+
is_bulky ? 'Bulky' : 'Heavy'
19+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/2525_categorize_box_according_to_criteria'
5+
require 'minitest/autorun'
6+
7+
class CategorizeBoxAccordingToCriteriaTest < ::Minitest::Test
8+
def test_default
9+
assert_equal('Heavy', categorize_box(1000, 35, 700, 300))
10+
assert_equal('Neither', categorize_box(200, 50, 800, 50))
11+
end
12+
13+
def test_additional
14+
assert_equal('Both', categorize_box(2909, 3968, 3272, 727))
15+
assert_equal('Bulky', categorize_box(92_487, 6200, 58_423, 40))
16+
end
17+
end

0 commit comments

Comments
 (0)