Level: Senior-Level
Round: Phone Screen · Type: Coding · Difficulty: 6/10 · Duration: 60 min · Interviewer: Neutral
Topics: Data Structures, Algorithms, Function Matching, Variadic Functions
Location: San Francisco Bay Area
Interview date: 2025-01-29
Got offer: False
Question: I had a 5-minute self-introduction, followed by a coding exercise on CodePad.
The coding exercise was divided into two parts:
Part 1: I was asked to write two functions:
` struct Function{ string name; vector<string> args; }; void register(vector<Function*> functions){
} vector<Function*> findMatch(vector<string> args){ } `
For example:
Function* A=new Function("A",{"Integer"}); Function* B=new Function("B",{"Integer","Boolean"}); Function* C=new Function("C",{"Integer","Boolean"}); register({A,B,C}); auto findMatch({"Integer"}); // should return A auto findMatch({"Integer","Boolean"}); // should return B,C
Part 2:
The challenge was to support variadic functions. I needed to modify the Function struct and the register function to accommodate functions with a variable number of arguments.
struct Function{ string name; vector<string> args; bool isCard; }; Function* A=new Function("A",{"Integer"},true); Function* B=new Function("B",{"Integer","Boolean"}); Function* C=new Function("C",{"Integer","Boolean"}); register({A,B,C}); auto findMatch({"Integer"}); // should return A auto findMatch({"Integer","Integer","Integer"}); // should return A auto findMatch({"Integer","Boolean"}); // should return B,C