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.
- Jesse and Cookies
- Discussions
Jesse and Cookies
Jesse and Cookies
Sort by
recency
|
169 Discussions
|
Please Login in order to post a comment
simple python solution
C# solution without PriorityQueue.
My thinking here is that it is only necessary to consider those mixed cookies whose sweetness < k for future calculations. Cookies with sweetness >= k are only necessary to consider when only 1 element < k remains alone at the end of the calculations.
In the example given it says:
If we have removed 6, 7 why is 7 back in A??
It say k = 7 and : sweetness = 1 * Least sweet cookie + 2 * 2nd least sweet cookie But my array was A{3,9} correct answer was : sweetness = 3 + (2*9)
Why?? 9 is least sweet cookie ?? It make my head hurt... So we don't need check the second value is sweetness or least sweet?
C++ O(nlogn)
The given parameters are meant to misguide you! my initial (not the optimal) solution was to use the given vector, sort it, erase the two elements in front, insert a new element according to the 1:2 given weight ratio. However, this is not the optimal solution:
the correct and optimal method to solve this question is to use a MinHeap (aka a priority queue with a std::greater comperator).
heres my version of the code: