Beautiful String Verification

Given a non-empty string inputString, determine if it can be converted into a 'Beautiful String' using the defined operation.

You can perform any number of operations to convert inputString into a 'Beautiful String'.

Operation:

Insert 'abc' into 'inputString'.
If 'inputString' is empty, simply insert 'abc'.
If 'inputString' is not empty, insert 'abc' at any position such that:
1. 'LEFT PORTION OF inputString' + 'abc' + 'RIGHT PORTION OF inputString' = 'Beautiful String'.
2. 'LEFT PORTION OF inputString' may be EMPTY OR 'a' OR 'ab' OR 'abc'.
3. 'RIGHT PORTION OF inputString' may be EMPTY OR 'c' OR 'bc' OR 'abc'.

Task:

Determine if inputString is already a 'Beautiful String' or not.

Input:

The first line contains an integer 'T' which denotes the number of test cases.
The following lines for each test case contain a string 'inputString'.

Output:

For each test case, print "True" if the string is a 'Beautiful String', otherwise print "False".

Example:

See the example below:

Input:
2
abcabcabc
abcabc
Output:
True
False

Constraints:

  • 1 <= T <= 100
  • 1 <= |inputString| <= 1000
  • The string inputString consists only of lowercase alphabets.
Note:
You do not need to handle any I/O operations; just implement the required function logic.
Be the first one to answer
Add answer anonymously...
Jaguar Land Rover Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter