Skip to content

Commit 28de4d6

Browse files
authored
Merge pull request #620 from fartem/2383_Minimum_Hours_of_Training_to_Win_a_Competition
2024-05-08 v. 5.6.3: added "2383. Minimum Hours of Training to Win a Competition"
2 parents 84140cc + 0e412ec commit 28de4d6

5 files changed

+42
-1
lines changed

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Style/GlobalVars:
1616
Enabled: false
1717
Style/MethodCalledOnDoEndBlock:
1818
Enabled: false
19+
Style/MultilineMethodSignature:
20+
Enabled: false
1921

2022
Bundler/GemComment:
2123
Enabled: false

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
423423
| 2367. Number of Arithmetic Triplets | [Link](https://leetcode.com/problems/number-of-arithmetic-triplets/) | [Link](./lib/easy/2367_number_of_arithmetic_triplets.rb) |
424424
| 2373. Largest Local Values in a Matrix | [Link](https://leetcode.com/problems/largest-local-values-in-a-matrix/) | [Link](./lib/easy/2373_largest_local_values_in_a_matrix.rb) |
425425
| 2379. Minimum Recolors to Get K Consecutive Black Blocks | [Link](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks/) | [Link](./lib/easy/2379_minimum_recolors_to_get_k_consecutive_black_blocks.rb) |
426+
| 2383. Minimum Hours of Training to Win a Competition | [Link](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition/) | [Link](./lib/easy/2383_minimum_hours_of_training_to_win_a_competition.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.6.2'
8+
s.version = '5.6.3'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
1111
s.executable = 'leetcode-ruby'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition/
4+
# @param {Integer} initial_energy
5+
# @param {Integer} initial_experience
6+
# @param {Integer[]} energy
7+
# @param {Integer[]} experience
8+
# @return {Integer}
9+
def min_number_of_hours(
10+
initial_energy,
11+
initial_experience,
12+
energy,
13+
experience
14+
)
15+
result = [energy.sum - initial_energy + 1, 0].max
16+
experience.each do |e|
17+
if initial_experience <= e
18+
result += e - initial_experience + 1
19+
initial_experience = e + 1
20+
end
21+
22+
initial_experience += e
23+
end
24+
25+
result
26+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/2383_minimum_hours_of_training_to_win_a_competition'
5+
require 'minitest/autorun'
6+
7+
class MinimumHoursOfTrainingToWinACompetitionTest < ::Minitest::Test
8+
def test_default
9+
assert_equal(8, min_number_of_hours(5, 3, [1, 4, 3, 2], [2, 6, 3, 1]))
10+
assert_equal(0, min_number_of_hours(2, 4, [1], [3]))
11+
end
12+
end

0 commit comments

Comments
 (0)