Skip to content

2025-04-24 v. 9.3.3: added "3210. Find the Encrypted String" #1023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
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 @@ -463,6 +463,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 3131. Find the Integer Added to Array I | [Link](https://leetcode.com/problems/find-the-integer-added-to-array-i/) | [Link](./lib/easy/3131_find_the_integer_added_to_array_i.rb) | [Link](./test/easy/test_3131_find_the_integer_added_to_array_i.rb) |
| 3136. Valid Word | [Link](https://leetcode.com/problems/valid-word/) | [Link](./lib/easy/3136_valid_word.rb) | [Link](./test/easy/test_3136_valid_word.rb) |
| 3151. Special Array I | [Link](https://leetcode.com/problems/special-array-i/) | [Link](./lib/easy/3151_special_array_i.rb) | [Link](./test/easy/test_3151_special_array_i.rb) |
| 3210. Find the Encrypted String | [Link](https://leetcode.com/problems/find-the-encrypted-string/) | [Link](./lib/easy/3210_find_the_encrypted_string.rb) | [Link](./test/easy/test_3210_find_the_encrypted_string.rb) |
| 3498. Reverse Degree of a String | [Link](https://leetcode.com/problems/reverse-degree-of-a-string/) | [Link](./lib/easy/3498_reverse_degree_of_a_string.rb) | [Link](./test/easy/test_3498_reverse_degree_of_a_string.rb) |

### Medium
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 = '9.3.2'
s.version = '9.3.3'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
s.executable = 'leetcode-ruby'
Expand Down
23 changes: 23 additions & 0 deletions lib/easy/3210_find_the_encrypted_string.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

# https://leetcode.com/problems/find-the-encrypted-string/
# @param {String} s
# @param {Integer} k
# @return {String}
def get_encrypted_string(s, k)
result = ::Array.new(s.size)

(0...s.size).each do |i|
if i + k < s.size
result << s[i + k]
else
index = i + k

index = (s.size - index).abs until index < s.size

result << s[index]
end
end

result.join
end
27 changes: 27 additions & 0 deletions test/easy/test_3210_find_the_encrypted_string.rb
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/easy/3210_find_the_encrypted_string'
require 'minitest/autorun'

class FindTheEncryptedStringTest < ::Minitest::Test
def test_default_one
assert_equal(
'tdar',
get_encrypted_string(
'dart',
3
)
)
end

def test_default_two
assert_equal(
'aaa',
get_encrypted_string(
'aaa',
1
)
)
end
end