651. Check If Word Is Valid After Substitutions

MediumStackStackString

A string is valid if it can be produced from an empty string by repeatedly inserting the substring "abc" at any position. Given a string s of the letters a, b, c, determine whether it is valid. Return true or false. The input is JSON {s}.

Input: JSON {s}.

Output: Boolean — true or false.

Examples

Example 1
Input: {"s":"aabcbc"}
Output: true
Explanation: Insert abc, then abc inside.
Example 2
Input: {"s":"abcabcababcc"}
Output: true
Explanation: A valid construction exists.
Example 3
Input: {"s":"abccba"}
Output: false
Explanation: Cannot be built from abc inserts.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →