We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Dynamic Programming
- Equal
- Discussions
Equal
Equal
Sort by
recency
|
459 Discussions
|
Please Login in order to post a comment
Hi, no code, but the solution idea is very simple:
To give to all except one means just to take from this one. So, the idea is to find the sum of "take" operations needed to make each item equal to the minimum.
However, it could be that the minimum is not reachable or reachable in a non-optimal way, so we should also consider taking from the minimum itself.
But it is senseless to take from the minimum the maximum piece or even more (it is obviously non-optimal — we will need to do the same with the rest as well). Therefore, we should consider possible alignments to
min
,min - 1
,min - 2
,min - 3
, andmin - 4
.Finally, just find the minimum of the sum of operations for each corresponding target.
Hello, here is my solution. It didn't passed the last test case, but it's a good path of understanding and how you can implement yours one.
Feel absolutely robbed on this one, this is an exercise that seemingly punishes efficiency. It should be comparing output AND operations, as I have completed 'Sample Test case 0' in the following operations: - 933 - 923 - 948 - 979 - 895 `
Iteration: 933, Largest: 4657, Smallest: 4657, Arr: 4657, ...n
I found something weird. If your program passed the problem, what is the output for this input?