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.
Hi everyone,
i need help :), well i'm alwayst get time limit at case 20 - 24. I already try to optimize my code using heap method. But i still got time limit,
This is my function in go lang:
func cookies(k int, pq *IntHeap) int32 {
var count int32
// for i := 0 ; i < len(A) ; i++{
// heap.Push(pq,A[i])
// }
for pq.Len() > 0{
smallA := heap.Pop(pq).(int)
if smallA < k {
if pq.Len() == 0{
count = -1
break
}else{
smallB := heap.Pop(pq).(int)
sum := smallA + 2 * smallB
heap.Push(pq,sum)
count++
fmt.Println(smallA,smallB,sum)
}
}else{
break
}
}
I hope somebody can give me tips for this problem :)
Thanks everyone
return count
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Jesse and Cookies
You are viewing a single comment's thread. Return to all comments →
Hi everyone, i need help :), well i'm alwayst get time limit at case 20 - 24. I already try to optimize my code using heap method. But i still got time limit, This is my function in go lang: func cookies(k int, pq *IntHeap) int32 {
I hope somebody can give me tips for this problem :) Thanks everyone
}