Skip to content

Commit e38f825

Browse files
committed
2023-11-15 v. 3.5.3: added "1700. Number of Students Unable to Eat Lunch"
1 parent 438029e commit e38f825

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
299299
| 1684. Count the Number of Consistent Strings | [Link](https://leetcode.com/problems/count-the-number-of-consistent-strings/) | [Link](./lib/easy/1684_count_the_number_of_consistent_strings.rb) |
300300
| 1688. Count of Matches in Tournament | [Link](https://leetcode.com/problems/count-of-matches-in-tournament/) | [Link](./lib/easy/1688_count_of_matches_in_tournament.rb) |
301301
| 1694. Reformat Phone Number | [Link](https://leetcode.com/problems/reformat-phone-number/) | [Link](./lib/easy/1694_reformat_phone_number.rb) |
302+
| 1700. Number of Students Unable to Eat Lunch | [Link](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/) | [Link](./lib/easy/1700_number_of_students_unable_to_eat_lunch.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 = '3.5.2'
8+
s.version = '3.5.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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/
4+
# @param {Integer[]} students
5+
# @param {Integer[]} sandwiches
6+
# @return {Integer}
7+
def count_students(students, sandwiches)
8+
arr = [0, 0]
9+
students.each { |s| arr[s] += 1 }
10+
sandwiches.each do |s|
11+
break if arr[s].zero?
12+
13+
arr[s] -= 1
14+
end
15+
16+
arr[0] + arr[1]
17+
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/1700_number_of_students_unable_to_eat_lunch'
5+
require 'minitest/autorun'
6+
7+
class NumberOfStudentsUnableToEatLunchTest < ::Minitest::Test
8+
def test_default
9+
assert_equal(0, count_students([1, 1, 0, 0], [0, 1, 0, 1]))
10+
assert_equal(3, count_students([1, 1, 1, 0, 0, 1], [1, 0, 0, 0, 1, 1]))
11+
end
12+
end

0 commit comments

Comments
 (0)