Hello, is it logically correct to calculate the average of the array values . Than iterate through the array and check : If the value is bigger than the average we check if we substrat k from it it becomes closer to the average value if not we do nothing. And we do the same if the value is bigger than the average (but by adding k) Than we print max-min
Here he says minH=Math.min(arr.get(0)+k,arr.get(i)-k); maxH=Math.max(arr.get(i+1)+k,arr.get(n-1)-k) BUT Gfg is not accepting the SAME for minimize the heights I Even after removing if(arr[i]-k
Problem Solution Link 🔗: ide.geeksforgeeks.org/online-cpp-compiler/e7e02956-97dd-46d9-9d1d-9fc4549c27ac
I think space complexity is O(N). not O(1) due to sort() function
That inituition using boxes of different sizes and pivot element is beautiful. Helped in visualizing a general case rather than numbers. Thank you!
Hello, is it logically correct to calculate the average of the array values .
Than iterate through the array and check :
If the value is bigger than the average we check if we substrat k from it it becomes closer to the average value if not we do nothing.
And we do the same if the value is bigger than the average (but by adding k)
Than we print max-min
Best explanation till date!! thanks
Nice explaination
very good explanation, thank you sir
Reducing the value by -k is sick! 23:51
i have one concern. there is one problem that we are assuming that largest element is arr[n-1] -k , there no way to check that this is negative
What if first element of array is >= k
Then if some i+1 is minimum it will get selected, else 0 th element will remain the minimum.
best explaination
Here he says
minH=Math.min(arr.get(0)+k,arr.get(i)-k);
maxH=Math.max(arr.get(i+1)+k,arr.get(n-1)-k)
BUT
Gfg is not accepting the SAME for minimize the heights I
Even after removing if(arr[i]-k
Literally good explanation & your face resemble to CarryMinati?
why i+1 came