I finished my Amazon onsite interview on June 2020. I was asked following question in the one of the rounds, Interviewer asked not to implement logic just specify datasturctures. I thought I have decent job with coding.
Recently Recruiter have contacted me to check If I am ready for interview and I have requested for feedback of previous interview. He informed me that my code didn't meet SDE2 standard for this question.
Since Leetcode has lot of smart and experienced developer I am posting here for feedback. If you were me how differently you would have coded?? Any design patters??
Design the classes & methods for an in-memory SQL library.
Below is the code I have written during the interview.
class DataBase {
List<Table> tables;
Map<String, Table> tableCatalog;
public DataBase() {
tables = new ArrayList();
tableCatalog = new HashMap();
}
// create table
public boolean createTable(String tableName) {
//
}
//return table
public Table getTableInstance(String tableName) {
}
}
class Table {
List<Row> rows;
Map<id, row> index;
public Table() {
rows = new ArrayList();
index = new HashMap();
}
//Insert row
public boolean insert(int id, String val) {
}
//select query
public String select(int id) {
}
//update query
publi boolean update(int id, String val) {
}
}
class Row {
int id;
String val;
public Row(int id, String val) {
this.id = id;
this.val = val;
}
public val getVal(id) {
}
public boolean setVal(id){
thi
}
}
Class User {
//create table
DataBase db;
Public User() {
db = new DataBase;
}
public CreateTable(table){
db.
}
}
// catalog admin//
User user = sesssion.getUser();
user.createTable(table);
Table table = user.getTableInstance(name);
table.insert(id, string)// true /false
table.select(id); //
table.update(id, string) //
//