The problem is not well defined since there are no negative examples.
For example, if they ask you in a medical school “what is the name of the device that amputates”, the “car” is technically correct, but probably not what they wanted to hear (because the number of car accidents ends with people with cut limbs). But whether there was a question: "What is the name of the instrument that the medical specialist will use to amputate during surgery," the answer can no longer be a "car."
Similarly, your solution will work for all the cases provided, but it is not as accurate as them. For example, "cba" recognized by your expression, but rejects them (at least not as a match for the entire string; a*b*c* trivially matches "cba" as a 0 length match anywhere in the string, and as a 1-bit match bit "a" ). In this case .* Is also a valid (but completely inaccurate) solution to their problem.
source share