Back to problems

Implement calculator and graph connectivity

Algorithm · Snapchat · Medium

1. Arithmetic Expression Evaluator Use a recursive-descent parser with separate parsing functions for expressions, terms, and factors. Multiplication and division are handled in parse_term, so they bind tighter than addition and subtraction. Example usage: Time complexity: $$O(len(expression))$$ Space complexity: $$O(depth\ of\ parentheses)$$ 2. Union-Find Connected Components Use Union-Find with path compression and union by rank. After processing all edges, group nodes by…

Checking your access…