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.
Have a question folks. I have solved this in a FP approach with immutable data structures. However, TC #5 onwards am hitting an OOM error.
My algo is very simple - use the scala set.subsets method to generate combinations of (1 to numberOfFriends) and then apply the given formula for each of these subsets, get the max of the applied formula.
The timeout is because the subsets and the further computation takes into account all the combinations. For ex: If a subset of length 3 achieves the maximum possible number of mangoes, the computation should stop there and not go ahead with subsets of lengths > 3. This is not the case here. What I'm trying to find out is how to do this without using a loop or in a pure functional approach. Can someone provide any clues ? I can message my Scala code if needed.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Mangoes
You are viewing a single comment's thread. Return to all comments →
Have a question folks. I have solved this in a FP approach with immutable data structures. However, TC #5 onwards am hitting an OOM error.
My algo is very simple - use the scala set.subsets method to generate combinations of (1 to numberOfFriends) and then apply the given formula for each of these subsets, get the max of the applied formula.
The timeout is because the subsets and the further computation takes into account all the combinations. For ex: If a subset of length 3 achieves the maximum possible number of mangoes, the computation should stop there and not go ahead with subsets of lengths > 3. This is not the case here. What I'm trying to find out is how to do this without using a loop or in a pure functional approach. Can someone provide any clues ? I can message my Scala code if needed.