• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
February 22, 2024 |620 Views
PROBLEM OF THE DAY : 21/02/2024 | Boolean Parenthesization
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Strings but also build up problem-solving skills.

In this problem, we are given a boolean expression s of length n with following symbols.
Symbols
   'T' ---> true
   'F' ---> false
and following operators filled between symbols
Operators
   &   ---> boolean AND
   |   ---> boolean OR
   ^   ---> boolean XOR
Count the number of ways we can parenthesize the expression so that the value of expression evaluates to true.

Note: The answer can be large, so return it with modulo 1003

Example :

Input: 
n = 7
s = T|T&F^T
Output: 
4
Explaination: 
The expression evaluates to true in 4 ways ((T|T)&(F^T)), (T|(T&(F^T))), (((T|T)&F)^T) and (T|((T&F)^T)).

Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/boolean-parenthesization5610/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp14-compiler/f95d2a26-8452-4572-b9f2-791e83eba7cf

Read More