[This question was removed due to Codility claiming it was taken from their interview practice]
the approach is discussed in the last answer of that stackoverflow post
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.