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.
I tried something very similar to this which did not work. I believe this is because choosing the first allowed value is not always best.
Consider the case N = 5, K = 5, [V_i] = [7, 1, 2, 7, 6]. The algorithm will pick [7, 1, 7], [2], [6] giving 3 subsets. But choosing [7, 1, 6], [2, 7] results in just 2 subsets.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Problem solving
You are viewing a single comment's thread. Return to all comments →
I tried something very similar to this which did not work. I believe this is because choosing the first allowed value is not always best. Consider the case N = 5, K = 5, [V_i] = [7, 1, 2, 7, 6]. The algorithm will pick [7, 1, 7], [2], [6] giving 3 subsets. But choosing [7, 1, 6], [2, 7] results in just 2 subsets.