Evaluate Expression To True

Given expression with operands and operators (OR , AND , XOR) , in how many ways can you evaluate the expression to true, by grouping in different ways? Operands are only true and false.
Input:
string : T|F&T^T here '|' will represent or operator '&' will represent and operator '^' will represent xor operator 'T' will represent true operand 'F' will false

Output:
different ways % MOD where MOD = 1003

Example:
string : T|F only 1 way (T|F) => T so output will be 1 % MOD = 1

Interview Code Editor
Hints
  • Hint 1
  • Solution Approach
  • Complete Solution
825 successful submissions.
Asked In:
  • Amazon
Click here to jump start your coding interview preparation