Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Leetcode 631. Design Excel Sum Formula
Design a spreadsheet supporting set/get and sum operations where sum formulas can reference individual cells and rectangular ranges; the core challenge is maintaining a dependency graph of formulas and efficiently propagating updates so dependent cells recompute correctly after any change.
Asked at:
Airbnb
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late March, 2025
Airbnb
Senior
Part 1: Set Value as Sum Your task is to design a data structure which allows you to set and retrieve (key, value) pairs. There are two cases: - The key is a string and the value is an integer. - The key is a string and the value is a list of strings (keys). The value of the cell is the *sum* of the value of the keys. API: > set_value(key: str, value: int) > set_sum(key: str, values: List[str]) > get_value(key: str) If the value of a key changes, any sum using that value should update as well. You may assume all calls are serial and there will be no cycles. If a key doesn't exist, you can treat its value as 0. An example sequence of actions: * set_value("A", 5) * set_value("B", 10) * set_sum("C", ["A", "A", "B"]) * set_sum("D", ["C", "C", "A"]) * get_value("A") # -> 5 * get_value("B") # -> 10 * get_value("C") # -> 20 * get_value("D") # -> 45 * set_value("A", 100) # Anything depending on "A" should update * get_value("D") # -> 520 D / | \ C A C visualization of the / | \ / | \ dependencies above A A B A A B
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.