[This question was removed due to Codility claiming it was taken from their interview practice]
What part of the problem description do you not understand? Where did you find this problem?
I don’t think the user was looking for the answer. I think the user was looking for guidance on how to approach the problem.
the approach is discussed in the last answer of that stackoverflow post
Several solutions are also shown. The point is to try and help guide by seeing what they do not understand. Anyone can Google to find the answers.
Whenever you are trying to solve algorithms is recommended to write pseudo code, it is extremely helpful. What are the necessary steps you need to take to solve this problem? You should also think about edge cases, for example the string “BALLOON” length is 7 and you need to form n number of instances of this word. So one thing that comes immediately to my mind is that if S length is less than 7, then the function should return 0, because no matter what characters we have in a string of which length is less than 7, we will never be able to form the string “BALLOON” because we need 7 characters at the very least to form this word.