Skip to content
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 @@ -698,6 +698,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 1457. Pseudo-Palindromic Paths in a Binary Tree | [Link](https://leetcode.com/problems/pseudo-palindromic-paths-in-a-binary-tree/) | [Link](./lib/medium/1457_pseudo_palindromic_paths_in_a_binary_tree.rb) | [Link](./test/medium/test_1457_pseudo_palindromic_paths_in_a_binary_tree.rb) |
| 1461. Check If a String Contains All Binary Codes of Size K | [Link](https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k/) | [Link](./lib/medium/1461_check_if_a_string_contains_all_binary_codes_of_size_k.rb) | [Link](./test/medium/test_1461_check_if_a_string_contains_all_binary_codes_of_size_k.rb) |
| 1472. Design Browser History | [Link](https://leetcode.com/problems/design-browser-history/) | [Link](./lib/medium/1472_design_browser_history.rb) | [Link](./test/medium/test_1472_design_browser_history.rb) |
| 1481. Least Number of Unique Integers after K Removals | [Link](https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/) | [Link](./lib/medium/1481_least_number_of_unique_integers_after_k_removals.rb) | [Link](./test/medium/test_1481_least_number_of_unique_integers_after_k_removals.rb) |
| 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) |
| 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) |
| 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) |
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 = '8.6.4'
s.version = '8.6.5'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
s.executable = 'leetcode-ruby'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

# https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/
# @param {Integer[]} arr
# @param {Integer} k
# @return {Integer}
def find_least_num_of_unique_ints(arr, k)
nums_with_count = ::Hash.new(0).tap { |h| arr.each { |num| h[num] += 1 } }
to_sort = nums_with_count.values.sort

count = 0
p = 0

while k.positive?
c = to_sort[p]

count += 1 if k >= c

k -= c
p += 1
end

nums_with_count.size - count
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/medium/1481_least_number_of_unique_integers_after_k_removals'
require 'minitest/autorun'

class LeastNumberOfUniqueIntegersAfterKRemovalsTest < ::Minitest::Test
def test_default_one
assert_equal(
1,
find_least_num_of_unique_ints(
[5, 5, 4],
1
)
)
end

def test_default_two
assert_equal(
2,
find_least_num_of_unique_ints(
[4, 3, 1, 1, 3, 3, 2],
3
)
)
end
end