-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #430 from fartem/1827_Minimum_Operations_to_Make_t…
…he_Array_Increasing 2023-12-15 v. 3.7.5: added "1827. Minimum Operations to Make the Array Increasing"
- Loading branch information
Showing
6 changed files
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
lib/easy/1827_minimum_operations_to_make_the_array_increasing.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
test/easy/test_1827_minimum_operations_to_make_the_array_increasing.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |