Ctrl K

Words From a Letter Pile

Easy
You have a pile of letters, given as the string pile. You may take letters from it in any order and assemble words from them; each letter in the pile can be used only once. Return how many complete copies of the word word you can assemble.
Example 1
pile="banananab", word="nab" → 2

The pile has 2 b's, 4 a's and 3 n's. Each copy of nab uses one of each, and the b's run out after two copies.

Example 2
pile="abc", word="aa" → 0

The word needs two a's, but the pile has only one.

Constraints
  • 1 ≤ len(pile) ≤ 100
  • 1 ≤ len(word) ≤ 10
  • pile and word consist of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNote From Clipped Letters EasyFirst One-Off Letter EasyWords Heard Only Once EasyWords From Letter Tiles EasyBalloon Signs From Letters Easy
loading Python…
Input
pile="banananab", word="nab"
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 118 tests on the server, hidden ones included.