Skip to content

Commit

Permalink
Merge pull request #430 from fartem/1827_Minimum_Operations_to_Make_t…
Browse files Browse the repository at this point in the history
…he_Array_Increasing

2023-12-15 v. 3.7.5: added "1827. Minimum Operations to Make the Array Increasing"
  • Loading branch information
fartem authored Dec 15, 2023
2 parents 1d2dbc6 + 528cfdb commit 000fb65
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 1812. Determine Color of a Chessboard Square | [Link](https://leetcode.com/problems/determine-color-of-a-chessboard-square/) | [Link](./lib/easy/1812_determine_color_of_a_chessboard_square.rb) |
| 1816. Truncate Sentence | [Link](https://leetcode.com/problems/truncate-sentence/) | [Link](./lib/easy/1816_truncate_sentence.rb) |
| 1822. Sign of the Product of an Array | [Link](https://leetcode.com/problems/sign-of-the-product-of-an-array/) | [Link](./lib/easy/1822_sign_of_the_product_of_an_array.rb) |
| 1827. Minimum Operations to Make the Array Increasing | [Link](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/) | [Link](./lib/easy/1827_minimum_operations_to_make_the_array_increasing.rb) |
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 = '3.7.4'
s.version = '3.7.5'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
s.executable = 'leetcode-ruby'
Expand Down
2 changes: 1 addition & 1 deletion lib/easy/1598_crawler_log_folder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# https://leetcode.com/problems/crawler-log-folder/
# @param {String[]} logs
# @return {Integer}
def min_operations(logs)
def _1598_min_operations(logs)
stack = []
logs.each do |log|
if log == '../'
Expand Down
22 changes: 22 additions & 0 deletions lib/easy/1827_minimum_operations_to_make_the_array_increasing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

# https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/
# @param {Integer[]} nums
# @return {Integer}
def _1827_min_operations(nums)
result = 0
curr = nums.first
(1...nums.length).each do |i|
num = nums[i]

if num <= curr
nxt = curr + 1
result += nxt - num
num = nxt
end

curr = num
end

result
end
6 changes: 3 additions & 3 deletions test/easy/test_1598_crawler_log_folder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class CrawlerLogFolderTest < ::Minitest::Test
def test_default
assert_equal(2, min_operations(%w[d1/ d2/ ../ d21/ ./]))
assert_equal(3, min_operations(%w[d1/ d2/ ./ d3/ ../ d31/]))
assert_equal(0, min_operations(%w[d1/ ../ ../ ../]))
assert_equal(2, _1598_min_operations(%w[d1/ d2/ ../ d21/ ./]))
assert_equal(3, _1598_min_operations(%w[d1/ d2/ ./ d3/ ../ d31/]))
assert_equal(0, _1598_min_operations(%w[d1/ ../ ../ ../]))
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/easy/1827_minimum_operations_to_make_the_array_increasing'
require 'minitest/autorun'

class MinimumOperationsToMakeTheArrayIncreasingTest < ::Minitest::Test
def test_default
assert_equal(3, _1827_min_operations([1, 1, 1]))
assert_equal(14, _1827_min_operations([1, 5, 2, 4, 1]))
assert_equal(0, _1827_min_operations([8]))
end
end

0 comments on commit 000fb65

Please sign in to comment.