Leetcode Problem 2408. Design SQL

2408. Design SQL

Leetcode Solutions

HashMap with Auto-Increment ID

  1. Initialize a HashMap tables to store table names mapped to their data.
  2. For each table, store a HashMap rows to map row IDs to actual rows and an integer nextRowId to keep track of the next ID to assign.
  3. Implement insertRow by adding a new row to the table's rows HashMap with the current nextRowId and then incrementing nextRowId.
  4. Implement deleteRow by removing the row with the given row ID from the table's rows HashMap. Do not modify nextRowId.
  5. Implement selectCell by accessing the cell in the table's rows HashMap using the given row ID and column ID.
  6. Note that column IDs are 1-indexed, so adjust the index when accessing the row.
UML Thumbnail

List of Lists with Row Deletion Tracking

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...