Ctrl K

Fill In to Repeated abc

Medium
You are given a string word made of the letters a, b and c. You may insert the letters a, b or c anywhere in it, as many times as you like. A string is **complete** when it consists of one or more copies of abc written back to back (abc, abcabc, abcabcabc and so on). Return the minimum number of insertions that make word complete.
Example 1
word='ca' → 4

Insert ab before c and bc after a to get abcabc: 4 letters in total.

Example 2
word='abcac' → 1

The first three letters already form abc; ac is missing a b in the middle, so one insertion is enough.

Example 3
word='bb' → 4

Each b needs its own copy of abc, which takes two insertions per b: 4 in total.

Constraints
  • 1 ≤ word.length ≤ 50
  • word consists only of the letters a, b and c
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBrackets With Wildcards MediumEvery Letter Once MediumErase Digits for the Smallest Number MediumSmallest Up-Down Sequence MediumBrackets to Patch In Medium
loading Python…
Input
word='ca'
Expected
4

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