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
8h

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
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter