What are the differences between clustered and non-clustered indexes?
Asked in the technical interview stage. Azure Data Engineer, 4-5 yrs exp.
Implement compare_indexes(records, key, query) using only Python data structures. A clustered index stores records ordered by key and locates matches with binary search. A non-clustered index preserves input order and maps each key to matching record IDs.
records is a list of dictionaries containing id and the selected key. Return clustered_ids, the matching IDs in sorted order, and non_clustered_ids, the matching IDs in original order.
Example: records with keys [30, 10, 20] and query 20 return matching ID lists containing the record with key 20. Duplicate keys must preserve their relative order.
def compare_indexes(records, key, query):