From a6779910146c6b13ec8283ade19039bad19776c4 Mon Sep 17 00:00:00 2001 From: fartem Date: Mon, 28 Apr 2025 08:20:47 +0300 Subject: [PATCH] 2025-04-28 v. 9.3.5: added "3046. Split the Array" --- .gitignore | 3 +++ README.md | 1 + leetcode-ruby.gemspec | 2 +- lib/easy/3046_split_the_array.rb | 16 ++++++++++++++++ test/easy/test_3046_split_the_array.rb | 23 +++++++++++++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 lib/easy/3046_split_the_array.rb create mode 100644 test/easy/test_3046_split_the_array.rb diff --git a/.gitignore b/.gitignore index 4131e1f1..419aaab6 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,6 @@ Gemfile.lock # Version checker *.remote + +# Cursor +.cursor diff --git a/README.md b/README.md index 6d76d8ae..20be482b 100644 --- a/README.md +++ b/README.md @@ -457,6 +457,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/). | 2951. Find the Peaks | [Link](https://leetcode.com/problems/find-the-peaks/) | [Link](./lib/easy/2951_find_the_peaks.rb) | [Link](./test/easy/test_2951_find_the_peaks.rb) | | 2966. Divide Array Into Arrays With Max Difference | [Link](https://leetcode.com/problems/divide-array-into-arrays-with-max-difference/) | [Link](./lib/easy/2966_divide_array_into_arrays_with_max_difference.rb) | [Link](./test/easy/test_2966_divide_array_into_arrays_with_max_difference.rb) | | 2974. Minimum Number Game | [Link](https://leetcode.com/problems/minimum-number-game/) | [Link](./lib/easy/2974_minimum_number_game.rb) | [Link](./test/easy/test_2974_minimum_number_game.rb) | +| 3046. Split the Array | [Link](https://leetcode.com/problems/split-the-array/) | [Link](./lib/easy/3046_split_the_array.rb) | [Link](./test/easy/test_3046_split_the_array.rb) | | 3083. Existence of a Substring in a String and Its Reverse | [Link](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/) | [Link](./lib/easy/3083_existence_of_a_substring_in_a_string_and_its_reverse.rb) | [Link](./test/easy/test_3083_existence_of_a_substring_in_a_string_and_its_reverse.rb) | | 3090. Maximum Length Substring With Two Occurrences | [Link](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences/) | [Link](./lib/easy/3090_maximum_length_substring_with_two_occurrences.rb) | [Link](./test/easy/test_3090_maximum_length_substring_with_two_occurrences.rb) | | 3110. Score of a String | [Link](https://leetcode.com/problems/score-of-a-string/) | [Link](./lib/easy/3110_score_of_a_string.rb) | [Link](./test/easy/test_3110_score_of_a_string.rb) | diff --git a/leetcode-ruby.gemspec b/leetcode-ruby.gemspec index ae2699e9..b879f6b0 100644 --- a/leetcode-ruby.gemspec +++ b/leetcode-ruby.gemspec @@ -5,7 +5,7 @@ require 'English' ::Gem::Specification.new do |s| s.required_ruby_version = '>= 3.0' s.name = 'leetcode-ruby' - s.version = '9.3.4' + s.version = '9.3.5' s.license = 'MIT' s.files = ::Dir['lib/**/*.rb'] + %w[README.md] s.executable = 'leetcode-ruby' diff --git a/lib/easy/3046_split_the_array.rb b/lib/easy/3046_split_the_array.rb new file mode 100644 index 00000000..27497206 --- /dev/null +++ b/lib/easy/3046_split_the_array.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# https://leetcode.com/problems/split-the-array/ +# @param {Integer[]} nums +# @return {Boolean} +def is_possible_to_split(nums) + count = {} + + nums.each do |num| + count[num] = count.fetch(num, 0) + 1 + + return false if count[num] == 3 + end + + true +end diff --git a/test/easy/test_3046_split_the_array.rb b/test/easy/test_3046_split_the_array.rb new file mode 100644 index 00000000..96366834 --- /dev/null +++ b/test/easy/test_3046_split_the_array.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require_relative '../test_helper' +require_relative '../../lib/easy/3046_split_the_array' +require 'minitest/autorun' + +class SplitTheArrayTest < ::Minitest::Test + def test_default_one + assert( + is_possible_to_split( + [1, 1, 2, 2, 3, 4] + ) + ) + end + + def test_default_two + assert( + !is_substring_present( + [1, 1, 1, 1] + ) + ) + end +end