Interview Question
- 0of 0 votes
AnswerDesign a system that supports updating table with options to discard the updates. It should have the following functions:
- create(String: rowName) #cannot be called until startTransaction has been called - delete(String: rowName) #cannot be called until startTransaction has been called - update(String: rowName) #cannot be called until startTransaction has been called - startTransaction() #start transaction operations( create/delete/update) - commitTransaction() #apply transaction to the actual Table( can be array-of-objects ) - discardTransaction() #discard any transaction applied thus far
Rough impl is acceptable as long as the design is displayed correctly.
- tnutty2k8 August 01, 2017 in United States| Report Duplicate | Flag | PURGE
Data Structures
Email me when people comment.
Email me when people comment.
Loading...
An error occurred in subscribing you.
Email me when people comment.
Email me when people comment.
Loading...
An error occurred in subscribing you.
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Three core ideas since the create/delete/update relies on structure of start/commit/discard
- tnutty2k8 August 03, 20171) When startTransaction is started, operate on a copy of the table then set or discard depending on commit/discard has been called
2) When startTransaction is started, queue up the operations, then only apply the operations if commit has been called else discard the operations
3) Have each operation have commit/discard feature. Each create operation keeps the rowName previous state before modifying the table. If commit is called, it discards the previous rowState and keeps the applied changes. Else if discard is called, it reapplies the prevRow state to the table. The higherLevel class would call commit/discard on each operations. Need to keep track of what operations has been applied.