
Asked in 42Gears Mobility Systems
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...
Top Mts1 Interview Questions Asked at 42Gears Mobility Systems
Q. Convert Binary Tree to Mirror Tree Convert a given binary tree into its mirror t...read more
Q. Matrix Element Cube Sum Problem For a given M x N sized 2D array 'MATRIX', find ...read more
Q. Cycle Detection in a Singly Linked List Determine if a given singly linked list ...read more
Interview Questions Asked to Mts1 at Other Companies
Top Skill-Based Questions for 42Gears Mobility Systems Mts1
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 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

