Expression Equality Checker
Given two strings representing expressions in variables, determine if they are equivalent. Return 'YES' if the expressions are identical and 'NO' if they are different. Each expression consists of lowercase alphabets, '+', '-', and parentheses. Assume at most 26 unique operands, ranging from 'a' to 'z'.
Explanation:
Two expressions are considered equivalent if they yield the same result when evaluated with any given assignments to their variables.
Input:
The first line contains an integer T, the number of test cases.
For each test case:
- First line: a string S1 representing the first expression
- Second line: a string S2 representing the second expression
Output:
For each test case, output 'YES' if the expressions are equivalent, otherwise 'NO'. Each result should be on a separate line.
Example:
Input:
2
(a + (b + c))
a + b + c
-(a-b+c)
c-b-a
Output:
YES
NO
Constraints:
- 1 ≤ T ≤ 10
- 1 ≤ |S1|, |S2| ≤ 1000
- Time Limit: 1 sec
Note:
Expressions are evaluated following the BODMAS rule.

AnswerBot
4mo
Check if two expressions are equivalent by evaluating them with different variable assignments.
Parse the expressions to evaluate them with different variable assignments.
Use a stack to keep track of o...read more
Help your peers!
Add answer anonymously...
42Gears Mobility Systems Mts1 interview questions & answers
A Mts1 was asked Q. Expression Equality Checker Given two strings representing expressions in variab...read more
A Mts1 was asked Q. Convert Binary Tree to Mirror Tree Convert a given binary tree into its mirror t...read more
A Mts1 was asked Q. Matrix Element Cube Sum Problem For a given M x N sized 2D array 'MATRIX', find ...read more
Popular interview questions of Mts1
A Mts1 was asked Q1. Expression Equality Checker Given two strings representing expressions in variab...read more
A Mts1 was asked Q2. Convert Binary Tree to Mirror Tree Convert a given binary tree into its mirror t...read more
A Mts1 was asked Q3. Matrix Element Cube Sum Problem For a given M x N sized 2D array 'MATRIX', find ...read more
>
42Gears Mobility Systems Mts1 Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

