A shipyard stencils an identification code onto every ballast crate before it ships. The code is always the word BALLAST, and the workers spell it out one letter at a time using embossed metal letter tiles pulled from a supply bin. Each completed code consumes exactly one tile of B, two tiles of A, two tiles of L, one tile of S, and one tile of T — no substitutions, and no tile can be reused once it has been used in a code.
The bin's entire current contents are given as a single string listing every uppercase tile currently available, in no particular order; the bin may also contain tiles of letters that never appear in BALLAST, which are simply irrelevant and can be ignored. Given the bin's contents, determine the maximum number of complete BALLAST codes the shipyard can stencil.
A single line containing a string S of uppercase English letters (A-Z), the current contents of the tile bin. S may be empty.
Print a single integer: the maximum number of complete BALLAST codes that can be assembled from the tiles in S.
Example 1
Input
ABLSTAL
Expected
1
Explanation
The bin has exactly A:2, B:1, L:2, S:1, T:1 — precisely enough tiles for one BALLAST code and no leftover for a second, so the answer is 1.
Example 2
Input
BBAAAALLLLSSTT
Expected
2
Explanation
The bin has B:2, A:4, L:4, S:2, T:2 — exactly twice the tiles needed per code for every required letter (B needs 1 per code -> 2/1=2, A needs 2 per code -> 4/2=2, L needs 2 -> 4/2=2, S needs 1 -> 2/1=2, T needs 1 -> 2/1=2), so two complete codes can be assembled with nothing left over, giving 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →