Skip to content

Commit e6b36c8

Browse files
committed
2025-02-14 v. 8.5.7: added "1395. Count Number of Teams"
1 parent ae36756 commit e6b36c8

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
689689
| 1381. Design a Stack With Increment Operation | [Link](https://leetcode.com/problems/design-a-stack-with-increment-operation/) | [Link](./lib/medium/1381_design_a_stack_with_increment_operation.rb) | [Link](./test/medium/test_1381_design_a_stack_with_increment_operation.rb) |
690690
| 1382. Balance a Binary Search Tree | [Link](https://leetcode.com/problems/balance-a-binary-search-tree/) | [Link](./lib/medium/1382_balance_a_binary_search_tree.rb) | [Link](./test/medium/test_1382_balance_a_binary_search_tree.rb) |
691691
| 1387. Sort Integers by The Power Value | [Link](https://leetcode.com/problems/sort-integers-by-the-power-value/) | [Link](./lib/medium/1387_sort_integers_by_the_power_value.rb) | [Link](./test/medium/test_1387_sort_integers_by_the_power_value.rb) |
692+
| 1395. Count Number of Teams | [Link](https://leetcode.com/problems/count-number-of-teams/) | [Link](./lib/medium/1395_count_number_of_teams.rb) | [Link](./test/medium/test_1395_count_number_of_teams.rb) |
692693
| 1400. Construct K Palindrome Strings | [Link](https://leetcode.com/problems/construct-k-palindrome-strings/) | [Link](./lib/medium/1400_construct_k_palindrome_strings.rb) | [Link](./test/medium/test_1400_construct_k_palindrome_strings.rb) |
693694
| 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) |
694695
| 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) |

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.5.6'
8+
s.version = '8.5.7'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/count-number-of-teams/
4+
# @param {Integer[]} rating
5+
# @return {Integer}
6+
def num_teams(rating)
7+
size = rating.size
8+
up = ::Array.new(size, 0)
9+
down = ::Array.new(size, 0)
10+
result = 0
11+
12+
(0...size).each do |i|
13+
i.downto(0) do |j|
14+
if rating[i] > rating[j]
15+
up[i] += 1
16+
result += up[j]
17+
end
18+
end
19+
end
20+
21+
(0...size).each do |i|
22+
i.downto(0) do |j|
23+
if rating[i] < rating[j]
24+
down[i] += 1
25+
result += down[j]
26+
end
27+
end
28+
end
29+
30+
result
31+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/1395_count_number_of_teams'
5+
require 'minitest/autorun'
6+
7+
class CountNumberOfTeamsTest < ::Minitest::Test
8+
def test_default_one = assert_equal(3, num_teams([2, 5, 3, 4, 1]))
9+
10+
def test_default_two = assert_equal(0, num_teams([2, 1, 3]))
11+
12+
def test_default_three = assert_equal(4, num_teams([1, 2, 3, 4]))
13+
end

0 commit comments

Comments
 (0)