Minimizing Operations On Increasing Array Values
Min operations to make all numbers in array increasing: iterate from end, update lower values with greatest divisor. Return -1 if no possible increase.
Problem class Solution { //one thing to note here is we have to get the values in increasing order, //the current values of nums[i] is the max value it can have after which it can only get a lower value. //start from the second last value in nums[] because last values is already the largest it can be public int minOperations(int[] nums) { int count = 0; //compare value at i-1th index with value at i, index if it is greater, update the value at i-1th index with its greatest divisor, if you get 1 as greatest divisor return -1; for (int i = nums.length-1;...