Skip to content

Commit e2fd2d7

Browse files
committed
2025-03-19 v. 9.0.2: added "2125. Number of Laser Beams in a Bank"
1 parent 167065d commit e2fd2d7

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
736736
| 2109. Adding Spaces to a String | [Link](https://leetcode.com/problems/adding-spaces-to-a-string/) | [Link](./lib/medium/2109_adding_spaces_to_a_string.rb) | [Link](./test/medium/test_2109_adding_spaces_to_a_string.rb) |
737737
| 2116. Check if a Parentheses String Can Be Valid | [Link](https://leetcode.com/problems/check-if-a-parentheses-string-can-be-valid/) | [Link](./lib/medium/2116_check_if_a_parentheses_string_can_be_valid.rb) | [Link](./test/medium/test_2116_check_if_a_parentheses_string_can_be_valid.rb) |
738738
| 2121. Intervals Between Identical Elements | [Link](https://leetcode.com/problems/intervals-between-identical-elements/) | [Link](./lib/medium/2121_intervals_between_identical_elements.rb) | [Link](./test/medium/test_2121_intervals_between_identical_elements.rb) |
739+
| 2125. Number of Laser Beams in a Bank | [Link](https://leetcode.com/problems/number-of-laser-beams-in-a-bank/) | [Link](./lib/medium/2125_number_of_laser_beams_in_a_bank.rb) | [Link](./test/medium/test_2125_number_of_laser_beams_in_a_bank.rb) |
739740
| 2425. Bitwise XOR of All Pairings | [Link](https://leetcode.com/problems/bitwise-xor-of-all-pairings/) | [Link](./lib/medium/2425_bitwise_xor_of_all_pairings.rb) | [Link](./test/medium/test_2425_bitwise_xor_of_all_pairings.rb) |
740741
| 2429. Minimize XOR | [Link](https://leetcode.com/problems/minimize-xor/) | [Link](./lib/medium/2429_minimize_xor.rb) | [Link](./test/medium/test_2429_minimize_xor.rb) |
741742
| 2657. Find the Prefix Common Array of Two Arrays | [Link](https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/) | [Link](./lib/medium/2657_find_the_prefix_common_array_of_two_arrays.rb) | [Link](./test/medium/test_2657_find_the_prefix_common_array_of_two_arrays.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 = '9.0.1'
8+
s.version = '9.0.2'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/number-of-laser-beams-in-a-bank/
4+
# @param {String[]} bank
5+
# @return {Integer}
6+
def number_of_beams(bank)
7+
lasers = []
8+
9+
bank.each do |b|
10+
lasers_at_b = b.count('1')
11+
12+
lasers << lasers_at_b if lasers_at_b.positive?
13+
end
14+
15+
result = 0
16+
17+
(1...lasers.size).each do |i|
18+
result += lasers[i - 1] * lasers[i]
19+
end
20+
21+
result
22+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/2125_number_of_laser_beams_in_a_bank'
5+
require 'minitest/autorun'
6+
7+
class NumberOfLaserBeamsInABankTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
8,
11+
number_of_beams(
12+
%w[
13+
011001
14+
000000
15+
010100
16+
001000
17+
]
18+
)
19+
)
20+
end
21+
22+
def test_default_two
23+
assert_equal(
24+
0,
25+
number_of_beams(
26+
%w[
27+
000
28+
111
29+
000
30+
]
31+
)
32+
)
33+
end
34+
end

0 commit comments

Comments
 (0)