Skip to content

2025-05-02 v. 9.3.7: added "3386. Button with Longest Push Time" #1028

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
May 2, 2025
Merged
Show file tree
Hide file tree
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
Expand Up @@ -466,6 +466,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 3151. Special Array I | [Link](https://leetcode.com/problems/special-array-i/) | [Link](./lib/easy/3151_special_array_i.rb) | [Link](./test/easy/test_3151_special_array_i.rb) |
| 3210. Find the Encrypted String | [Link](https://leetcode.com/problems/find-the-encrypted-string/) | [Link](./lib/easy/3210_find_the_encrypted_string.rb) | [Link](./test/easy/test_3210_find_the_encrypted_string.rb) |
| 3280. Convert Date to Binary | [Link](https://leetcode.com/problems/convert-date-to-binary/) | [Link](./lib/easy/3280_convert_date_to_binary.rb) | [Link](./test/easy/test_3280_convert_date_to_binary.rb) |
| 3386. Button with Longest Push Time | [Link](https://leetcode.com/problems/button-with-longest-push-time/) | [Link](./lib/easy/3386_button_with_longest_push_time.rb) | [Link](./test/easy/test_3386_button_with_longest_push_time.rb) |
| 3498. Reverse Degree of a String | [Link](https://leetcode.com/problems/reverse-degree-of-a-string/) | [Link](./lib/easy/3498_reverse_degree_of_a_string.rb) | [Link](./test/easy/test_3498_reverse_degree_of_a_string.rb) |
| 3516. Find Closest Person | [Link](https://leetcode.com/problems/find-closest-person/) | [Link](./lib/easy/3516_find_closest_person.rb) | [Link](./test/easy/test_3516_find_closest_person.rb) |

Expand Down
2 changes: 1 addition & 1 deletion leetcode-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'English'
::Gem::Specification.new do |s|
s.required_ruby_version = '>= 3.0'
s.name = 'leetcode-ruby'
s.version = '9.3.6'
s.version = '9.3.7'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
s.executable = 'leetcode-ruby'
Expand Down
21 changes: 21 additions & 0 deletions lib/easy/3386_button_with_longest_push_time.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

# https://leetcode.com/problems/button-with-longest-push-time/
# @param {Integer[][]} events
# @return {Integer}
def button_with_longest_time(events)
max_time = events[0][1]
result = events[0][0]

(1...events.size).each do |i|
press_time = events[i][1] - events[i - 1][1]

next unless press_time > max_time || press_time == max_time && events[i][0] < result

max_time = press_time

result = events[i][0]
end

result
end
33 changes: 33 additions & 0 deletions test/easy/test_3386_button_with_longest_push_time.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/easy/3386_button_with_longest_push_time'
require 'minitest/autorun'

class ButtonWithLongestPushTimeTest < ::Minitest::Test
def test_default_one
assert_equal(
1,
button_with_longest_time(
[
[1, 2],
[2, 5],
[3, 9],
[1, 15]
]
)
)
end

def test_default_two
assert_equal(
10,
button_with_longest_time(
[
[10, 5],
[1, 7]
]
)
)
end
end