- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find minimum operations to make the array increasing using Python

Suppose we have an array nums. In one operation, we can select one element of the array and increase it by 1. For example, if we have [4,5,6], we can select element at index 1 to make the array [4,5,5]. Then we have to find the minimum number of operations required to make nums strictly increasing.

So, if the input is like nums = [8,5,7], then the output will be 7, because we need to increase like [8,6,7],[8,7,7],[8,8,7],[8,9,7],[8,9,8],[8,9,9],[8,9,10].

To solve this, we will follow these steps −

count:= 0

for i in range 0 to size of nums - 1, do

if nums[i+1] −= nums[i], then

count := count + nums[i] - nums[i+1] + 1

nums[i+1] := nums[i+1] + nums[i] - nums[i+1] + 1

return count

Let us see the following implementation to get better understanding −

## Example

def solve(nums): count=0 for i in range(len(nums)-1): if nums[i+1]<=nums[i]: count+=nums[i]-nums[i+1]+1 nums[i+1]+=nums[i]-nums[i+1]+1 return count nums = [8,5,7] print(solve(nums))

## Input

[8,5,7]

## Output

7

- Related Questions & Answers
- Program to find minimum operations to make array equal using Python
- Program to find minimum number of operations required to make lists strictly Increasing in python
- Program to find minimum one bit operations to make integers zero in Python
- Program to find minimum number of operations to make string sorted in Python
- Find minimum operations needed to make an Array beautiful in C++
- Program to find minimum operations needed to make two arrays sum equal in Python
- Program to find minimum moves to make array complementary in Python
- Program to find minimum numbers of function calls to make target array using Python
- Program to find minimum number of operations required to make one number to another in Python
- C++ program to find minimum how many operations needed to make number 0
- Find minimum number of merge operations to make an array palindrome in C++
- Minimum operations to make XOR of array zero in C++
- Golang Program to find the minimum and maximum number, using binary operations.
- Minimum operations required to make all the array elements equal in C++
- Program to find minimum number of operations required to make one string substring of other in Python

Advertisements