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.
Be the first one to answer
Add answer anonymously...
Top 42Gears Mobility Systems Mts1 interview questions & answers
Popular interview questions of Mts1
>
42Gears Mobility Systems Mts1 Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app