MCPcopy Create free account
hub / github.com/Rohit91singh9/Coding-DP-DSA / PowerNonDecreasing

Class PowerNonDecreasing

PowerNonDecreasing.java:1–18  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1public class PowerNonDecreasing {
2static int makePowerNonDecreasing(int[] power,int n)
3{
4 if(n==1)
5 return 0;
6 int sum=0;
7 for(int i=0;i<n-1;i++){
8 if(power[i]>power[i+1]){
9 int val=power[i]-power[i+1];
10 sum += val;
11 for(int j=i+1;j<n;j++){
12 power[j]=power[j]+val;
13 } // inner loop end
14 } // if loop end
15 } // outer loop end
16 return sum;
17}
18}
19
20// Time complexity is always less than O(n2)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected