I'm Kay, a cloud consultant focusing on cloud migration to Google Cloud. Passionate about simplifying Cloud Confusion, I've made it my mission to help young professionals enter the cloud world.
Location
Berlin
Education
Bachelor of Science - Business Information Systems
Work
Consultant - Cloud Transformation and Systems Engineering
The startingPoint - 1 is adjusting that the formula would be excluding the min and we want to include it. In general it seems to be working quiet well.
The advantage here also is that it only has to execute 2 operations no matter how large the span is.
This would decrease the time complexity to O(1). Which is quiet nice.
I am a Software Engineer and Developer Advocate who loves sharing knowledge via writing, videos, mentorship, and working out. Please Subscribe: https://www.youtube.com/channel/UCcz5Bvr4kGHPFAjvnRhIQ4g
I'm Kay, a cloud consultant focusing on cloud migration to Google Cloud. Passionate about simplifying Cloud Confusion, I've made it my mission to help young professionals enter the cloud world.
Location
Berlin
Education
Bachelor of Science - Business Information Systems
Work
Consultant - Cloud Transformation and Systems Engineering
Yeah. You either have to add the min value or subtract minManipulation(array[0]-1) because otherwise it will exclude the lower boundary. So I corrected the formula to reflect this change (just in case anybody is interested in this).
I am a Software Engineer and Developer Advocate who loves sharing knowledge via writing, videos, mentorship, and working out. Please Subscribe: https://www.youtube.com/channel/UCcz5Bvr4kGHPFAjvnRhIQ4g
I tried to implement the algorithm myself and came up with a solution that is utilizing the formula for sums by Gauss.
IDK how to explain the equation but it would look like this:
I implemented this in typescript to see if it works:
The
startingPoint - 1
is adjusting that the formula would be excluding the min and we want to include it. In general it seems to be working quiet well.The advantage here also is that it only has to execute 2 operations no matter how large the span is.
This would decrease the time complexity to O(1). Which is quiet nice.
Kay, thank you for your suggestion. This is how I did it with
javascript
:So, I had to add the lower boundary (min value) to the final answer to make it work properly.
Yeah. You either have to add the
min
value or subtractminManipulation(array[0]-1)
because otherwise it will exclude the lower boundary. So I corrected the formula to reflect this change (just in case anybody is interested in this).Looking Good 💪