Airbnb interview
Questions4
The basic level of the in-memory database contains records. Each record can be accessed with a unique identifier key, which is of string type. A record contains several field - value pairs, with field as string type and value as integer type. All operations have a timestamp parameter — a stringified timestamp in milliseconds. It is guaranteed that all timestamps are unique and are in a range from 0 to 109. Operations will be given in order of strictly increasing timestamps. Timestamps will be needed starting from Level 3. - set(self, timestamp: int, key: str, field: str, value: int) -> None — should insert a field - value pair to the record associated with key. If the field in the record already exists, replace the existing value with the specified value. If the record does not exist, a new one is created. - compare_and_set(self, timestamp: int, key: str, field: str, expected_value: int, new_value: int) -> bool — should update the value of field in the record associated with key to new_value if the current value equals expected_value. If expected_value does not match the current value, or either key or field does not exist, this operation is ignored. This operation should return True if the field was updated and False otherwise. - compare_and_delete(self, timestamp: int, key: str, field: str, expected_value: int) -> bool — should remove the field field in the record associated with key if the previous value equals expected_value. If expected_value does not match the current value, or either key or field does not exist, this operation is ignored. This operation should return True if the field was removed and False otherwise. - get(self, timestamp: int, key: str, field: str) -> int | None — should return the value contained within field of the record associated with key. If the record or the field does not exist, should return None.
The database should support displaying data based on filters. Introduce an operation to support printing some fields of a record. - **scan(self, timestamp: int, key: str) -> list[str]** — should return a list of strings representing the fields of the record associated with key. The returned list should be in the following format ["<field_1>(<value_1>)", "<field_2>(<value_2>)", ...], where fields are sorted lexicographically. If the specified record does not exist, returns an empty list. - **scan_by_prefix(self, timestamp: int, key: str, prefix: str) -> list[str]** — should return a list of strings representing some fields of the record associated with key. Specifically, only fields that start with prefix should be included. The returned list should be in the same format as in the scan operation with fields sorted in lexicographical order.
2 more questions from this interview
A subscription opens every question, and Copilot suggests answers live during your Airbnb interview.
Sign in to unlockSummarized questions based on candidates' accounts. These materials do not represent the official position of the companies and do not disclose internal processes. If you believe a publication violates your rights — contact us.