PROBLEM:Chef Purchased an array A having N Integer values,After Playing it for while,he got bored of it and decided to update value of its element.In one second he can increase value of each array element by 1.He wants each array element’s value to become greater than or equal to K.
Please Help Chef to find out the minimum amount of time it will take,for him to do so…
EXPLANATION:Since we can only increase all the elements by 1, the minimum element will take most step to reach K.So we have to find the minimum element in array A and answer will difference between K and minimum element.
One corner case is if K is less than minimum element in the array A
AUTHOR’S AND TESTER’S SOLUTIONS:
We can also use Sorting(Bubble,Quick,etc) to find minimum element in Array, but this will increase time complexity