Skip to content

Commit 38993d4

Browse files
authored
2025-03-11 v. 8.9.1: added "1996. The Number of Weak Characters in the Game"
2 parents 3ca6c66 + 739971d commit 38993d4

4 files changed

+71
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
724724
| 1877. Minimize Maximum Pair Sum in Array | [Link](https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/) | [Link](./lib/medium/1877_minimize_maximum_pair_sum_in_array.rb) | [Link](./test/medium/test_1877_minimize_maximum_pair_sum_in_array.rb) |
725725
| 1910. Remove All Occurrences of a Substring | [Link](https://leetcode.com/problems/remove-all-occurrences-of-a-substring/) | [Link](./lib/medium/1910_remove_all_occurrences_of_a_substring.rb) | [Link](./test/medium/test_1910_remove_all_occurrences_of_a_substring.rb) |
726726
| 1985. Find the Kth Largest Integer in the Array | [Link](https://leetcode.com/problems/find-the-kth-largest-integer-in-the-array/) | [Link](./lib/medium/1985_find_the_kth_largest_integer_in_the_array.rb) | [Link](./test/medium/test_1985_find_the_kth_largest_integer_in_the_array.rb) |
727+
| 1996. The Number of Weak Characters in the Game | [Link](https://leetcode.com/problems/the-number-of-weak-characters-in-the-game/) | [Link](./lib/medium/1996_the_number_of_weak_characters_in_the_game.rb) | [Link](./test/medium/test_1996_the_number_of_weak_characters_in_the_game.rb) |
727728
| 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) |
728729
| 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) |
729730
| 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) |

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 = '8.9.0'
8+
s.version = '8.9.1'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/the-number-of-weak-characters-in-the-game/
4+
# @param {Integer[][]} properties
5+
# @return {Integer}
6+
def number_of_weak_characters(properties)
7+
properties.sort_by! { |a| [a[0], -a[1]] }
8+
9+
result = 0
10+
n = properties.length
11+
max = properties[-1][1]
12+
13+
(n - 2).downto(0) do |i|
14+
curr = properties[i][1]
15+
16+
if curr < max
17+
result += 1
18+
else
19+
max = curr
20+
end
21+
end
22+
23+
result
24+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/1996_the_number_of_weak_characters_in_the_game'
5+
require 'minitest/autorun'
6+
7+
class TheNumberOfWeakCharactersInTheGameTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
0,
11+
number_of_weak_characters(
12+
[
13+
[5, 5],
14+
[6, 3],
15+
[3, 6]
16+
]
17+
)
18+
)
19+
end
20+
21+
def test_default_two
22+
assert_equal(
23+
1,
24+
number_of_weak_characters(
25+
[
26+
[2, 2],
27+
[3, 3]
28+
]
29+
)
30+
)
31+
end
32+
33+
def test_default_three
34+
assert_equal(
35+
1,
36+
number_of_weak_characters(
37+
[
38+
[1, 5],
39+
[10, 4],
40+
[4, 3]
41+
]
42+
)
43+
)
44+
end
45+
end

0 commit comments

Comments
 (0)