![]() |
VOOZH | about |
Given a string S, the task is to design a Deterministic Finite Automata (DFA) for accepting the language L = C (A + B)+. If the given string is accepted by DFA, then print "Yes". Otherwise, print "No".
Examples:
Input: S = "CABABABAB"
Output: Yes
Explanation: The given string is of the form C(A + B)+ as the first character is C and it is followed by A or B.Input: S = "ABAB"
Output: No
Approach: The idea is to interpret the given language L = C (A + B)+ and for the regular expression of the form C(A + B)+, the following is the DFA State Transition Diagram:
👁 ImageFollow the steps below to solve the problem:
Below is the implementation of the above approach:
Yes
Time Complexity: O(N)
Auxiliary Space: O(1)