You are viewing a single comment's thread. Return to all comments →
Even though I'm heapifying the array only once and using min-heap to store and operate on the data, I'm getting timeouts from cases #20, #21, #22 and #23. (large inputs)
My submission is here: https://www.hackerrank.com/challenges/jesse-and-cookies/submissions/code/28210608 any ideas how I can make this faster? I could not spot any issues with my heap, my pop/push operations are O(logn).
Hi, the submission code takes about 16 seconds on my machine and profiling shows almost all the time goes to the down function. The file input23.txt has one million 1 values. I did not look at the code or debug it, but an idea is maybe what is happening is your down function should be stopping at the root because arr==arr==arr, but instead propagates identical values from the root all the way to the leaf?
I was unable to find out why it was timeout ,eventhough its correct for arr==arr==arr
What was the reason for the timeout?
Can you explain what the fact that the root has same values as his children tells you about the rest of the heap?
I had persistent timeout from #20 similarly. You should never be computing the length of the heap--for me, this required a try/except statement in Python that finally did the trick.