Find Banks From Identifier Mappings
Company: Plaid
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's ability to design efficient lookup and preprocessing data structures for mapping identifiers to bank records, including reasoning about handling missing codes and duplicate entries, relevant to a Machine Learning Engineer role.
Constraints
- 0 <= len(code_to_institution), len(institution_to_banks), len(queries) <= 2 * 10^5
- The total number of bank names across all institution lists is at most 2 * 10^5
- Codes, institution IDs, and bank names are strings
- Duplicate bank names may appear in the same institution's list
- Average-case O(1) hash map lookups are expected
Examples
Input: ({"C001": "inst_1", "C002": "inst_2", "C003": "inst_1"}, {"inst_1": ["Bank A", "Bank A Savings"], "inst_2": ["Bank B"]}, ["C001", "C002", "UNKNOWN", "C003"])
Expected Output: [["Bank A", "Bank A Savings"], ["Bank B"], [], ["Bank A", "Bank A Savings"]]
Explanation: C001 and C003 both map to inst_1, so they return the same bank list. UNKNOWN is not a known code, so it returns an empty list.
Input: ({"X1": "i1", "X2": "i2", "X3": "i_missing"}, {"i1": ["Alpha Bank", "Alpha Bank", "Beta Credit", "Alpha Bank"], "i2": []}, ["X1", "X2", "X3", "NOPE"])
Expected Output: [["Alpha Bank", "Beta Credit"], [], [], []]
Explanation: Duplicate bank names for i1 are removed while preserving order. X3 points to an institution with no bank list, and NOPE is an unknown code.
Input: ({}, {}, ["ANY"])
Expected Output: [[]]
Explanation: With no mappings at all, every query returns an empty list.
Input: ({"A": "inst_single"}, {"inst_single": ["Solo Bank"]}, [])
Expected Output: []
Explanation: If there are no queries, the result is an empty list.
Hints
- A bank code does not map directly to banks. First map code -> institution, then institution -> banks.
- To remove duplicates while preserving order, keep a `set` of seen bank names and append only the first time you encounter each one.