Skip to content

Conversation

@Gumparthypavankumar
Copy link

  1. What is now different from before?

The implementation now reverses the numbers and operators stacks before applying + and - operators.This ensures that + and - are evaluated in left-to-right order, which matches the expected behavior of the expression (i.e., left-associative evaluation). Previously, operators were applied in reverse order, leading to incorrect results like 1-1+1 → -1 instead of 1.

  1. What is the reason for the change?
  • and - are left-associative operators with the same precedence, and must be processed in the order they appear.
  1. Anything to watch out for?

Space complexity increases slightly due to the temporary numRev and opRev stacks, but remains O(n).

1. What is now different from before?
> The implementation now reverses the numbers and operators stacks before applying + and - operators.This ensures that + and - are evaluated in left-to-right order, which matches the expected behavior of the expression (i.e., left-associative evaluation). Previously, operators were applied in reverse order, leading to incorrect results like 1-1+1 → -1 instead of 1.
2. What is the reason for the change?
> + and - are left-associative operators with the same precedence, and must be processed in the order they appear.
3. Anything to watch out for?
> Space complexity increases slightly due to the temporary numRev and opRev stacks, but remains O(n).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant