From ee1a786566495554645ffa80e0661b1eaa9748c0 Mon Sep 17 00:00:00 2001 From: fartem Date: Tue, 28 Jan 2025 12:24:05 +0300 Subject: [PATCH] 2025-01-28 v. 8.3.1: added "1111. Maximum Nesting Depth of Two Valid Parentheses Strings" --- README.md | 1 + leetcode-ruby.gemspec | 2 +- ..._depth_of_two_valid_parentheses_strings.rb | 14 +++++++++++ ..._depth_of_two_valid_parentheses_strings.rb | 25 +++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 lib/medium/1111_maximum_nesting_depth_of_two_valid_parentheses_strings.rb create mode 100644 test/medium/test_1111_maximum_nesting_depth_of_two_valid_parentheses_strings.rb diff --git a/README.md b/README.md index e8ee9b43..80e1d028 100644 --- a/README.md +++ b/README.md @@ -663,6 +663,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/). | 1079. Letter Tile Possibilities | [Link](https://leetcode.com/problems/letter-tile-possibilities/) | [Link](./lib/medium/1079_letter_tile_possibilities.rb) | [Link](./test/medium/test_1079_letter_tile_possibilities.rb) | | 1081. Smallest Subsequence of Distinct Characters | [Link](https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/) | [Link](./lib/medium/1081_smallest_subsequence_of_distinct_characters.rb) | [Link](./test/medium/test_1081_smallest_subsequence_of_distinct_characters.rb) | | 1110. Delete Nodes And Return Forest | [Link](https://leetcode.com/problems/delete-nodes-and-return-forest/) | [Link](./lib/medium/1110_delete_nodes_and_return_forest.rb) | [Link](./test/medium/test_1110_delete_nodes_and_return_forest.rb) | +| 1111. Maximum Nesting Depth of Two Valid Parentheses Strings | [Link](https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings/) | [Link](./lib/medium/1111_maximum_nesting_depth_of_two_valid_parentheses_strings.rb) | [Link](./test/medium/test_1111_maximum_nesting_depth_of_two_valid_parentheses_strings.rb) | | 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) | | 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) | diff --git a/leetcode-ruby.gemspec b/leetcode-ruby.gemspec index 4b989725..ebc3cba1 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 = '8.3.0' + s.version = '8.3.1' s.license = 'MIT' s.files = ::Dir['lib/**/*.rb'] + %w[README.md] s.executable = 'leetcode-ruby' diff --git a/lib/medium/1111_maximum_nesting_depth_of_two_valid_parentheses_strings.rb b/lib/medium/1111_maximum_nesting_depth_of_two_valid_parentheses_strings.rb new file mode 100644 index 00000000..ffbff48d --- /dev/null +++ b/lib/medium/1111_maximum_nesting_depth_of_two_valid_parentheses_strings.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings/ +# @param {String} seq +# @return {Integer[]} +def max_depth_after_split(seq) + result = ::Array.new(seq.size) + + seq.each_char.with_index do |char, i| + result[i] = char == '(' ? i & 1 : 1 - (i & 1) + end + + result +end diff --git a/test/medium/test_1111_maximum_nesting_depth_of_two_valid_parentheses_strings.rb b/test/medium/test_1111_maximum_nesting_depth_of_two_valid_parentheses_strings.rb new file mode 100644 index 00000000..dfe373ef --- /dev/null +++ b/test/medium/test_1111_maximum_nesting_depth_of_two_valid_parentheses_strings.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require_relative '../test_helper' +require_relative '../../lib/medium/1111_maximum_nesting_depth_of_two_valid_parentheses_strings' +require 'minitest/autorun' + +class MaximumNestingDepthOfTwoValidParenthesesStringsTest < ::Minitest::Test + def test_default_one + assert_equal( + [0, 1, 1, 1, 1, 0], + max_depth_after_split( + '(()())' + ) + ) + end + + def test_default_two + assert_equal( + [0, 0, 0, 1, 1, 0, 0, 0], + max_depth_after_split( + '()(())()' + ) + ) + end +end