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.word='ca' → 4
Insert ab before c and bc after a to get abcabc: 4 letters in total.
word='abcac' → 1
The first three letters already form abc; ac is missing a b in the middle, so one insertion is enough.
word='bb' → 4
Each b needs its own copy of abc, which takes two insertions per b: 4 in total.
word.length ≤ 50word consists only of the letters a, b and cword='ca'
4
Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.