![]() |
VOOZH | about |
Given a string S of length N representing a boolean expression, the task is to find the minimum number of AND, OR, and NOT gates required to realize the given expression.
Examples:
Input: S = "A+B.C"
Output: 2
Explanation: Realizing the expression requires 1 AND gate represented by '.' and 1 OR gate represented by '+'.Input: S = "(1 - A). B+C"
Output: 3
Explanation: Realizing the expression requires 1 AND gate represented by '.' and 1 OR gate represented by '+' and 1 NOT gate represented by '-'.
Approach: Follow the steps below to solve the problem:
Below is the implementation of the above approach:
3
Time Complexity: O(N)
Auxiliary Space: O(1)