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.
For b number combination, the sum distributes between min and max continuously.(min and max could be calculated by math method.)
So if k in the range, there is a solution.
Then we only need to add on min until it equals to k. How much is required for each number to be added could be calculated easily.
This is easy because we only need to output one legal solution.
Example:
12 8 3
we could start fron 1 2 3, add 2 to each items, then we got 3 4 5 which is a solution.
Hint: 2 is got by (k - min)/b and if need there will be calculate about (k - min)%b
With this method, effiency is based on O(b).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bonetrousle
You are viewing a single comment's thread. Return to all comments →
For b number combination, the sum distributes between min and max continuously.(min and max could be calculated by math method.) So if k in the range, there is a solution. Then we only need to add on min until it equals to k. How much is required for each number to be added could be calculated easily.
This is easy because we only need to output one legal solution. Example: 12 8 3
we could start fron 1 2 3, add 2 to each items, then we got 3 4 5 which is a solution.
Hint: 2 is got by (k - min)/b and if need there will be calculate about (k - min)%b
With this method, effiency is based on O(b).