Implement a command-driven in-memory key–value database. Supported commands (one per line):
-
SET key value
-
GET key → print value or NULL
-
DELETE key
-
COUNT value → print how many keys currently map to this value
-
BEGIN → start a transaction
-
ROLLBACK → undo changes in the most recent open transaction; if none, print NO TRANSACTION
-
COMMIT → make all open transaction changes permanent. Constraints: up to 100,000 commands; keys and values are ASCII strings; average O(
-
per operation; memory must remain within reasonable bounds. Design data structures to support COUNT efficiently and implement transactional semantics using an undo log or equivalent. Specify I/O format precisely and discuss edge cases (nested transactions, deleting non-existent keys, multiple keys sharing a value).