Ctrl K

Grown From "abc"

Medium
Start with an empty string. In one step you may insert the three letters "abc" together anywhere in the current string: at the start, at the end, or between any two characters. Given a string text, return true if it can be built by such steps, and false otherwise.
Example 1
text="ababcc" → True

"" → "abc" → "ab" + "abc" + "c" = "ababcc".

Example 2
text="abcabcabc" → True

Three inserts of "abc", each at the end.

Example 3
text="acbabc" → False

Removing the trailing "abc" leaves "acb", which no sequence of inserts can produce.

Constraints
  • 1 ≤ len(text) ≤ 2 · 10⁵
  • text 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 problemsTidy a Folder Route MediumFour-Operation Calculator MediumEvery Letter Once MediumChecking a Tree Record With Hash Marks MediumLongest Path to a File Medium
loading Python…
Input
text="ababcc"
Expected
True

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