My Journey from Econ PhD to Tech — Part 5: Q&A + Miscellaneous
By: Scarlet Chen
Tags: Networking, Job Hunting, Recruiting, Economics, Tech

Q: How much coding do I need to know? What’s a coding interview like?

A: First, if you only know Stata and nothing else, Amazon is the only tech firm that will embrace you, so pick up either Python or R if you can. (But seriously, if you’ll stay in tech for the rest of your career, knowing coding is valuable beyond just interviewing — there are people who started at Amazon and can’t switch jobs because they only know Stata)

Second, the amount of coding you need to know to get the job varies by firm. Firms will typically send you interview prep material before your interview, so you would know how much coding the interview involves. But of course, it’ll be too late to prepare then.

I’d say, if you know everything I listed here, you’re fine. And in fact, it’s not so much about remembering these commands/algorithm/data structures, but that once you have mastered these, you’re at a level that can solve most coding questions that come up in data science interviews.

In other words: in a data science interview, they won’t ask you to write a function to implement ‘heap’, but they will ask you a question, which, in order to solve it, you will need to use the data structure heap (there are of course other ways to solve it, but knowing how heap works and using heap in your solution makes solving that problem very easy). — I’m using ‘heap’ as an example… not saying that all coding interviews involve heap if that wasn’t clear

All data science coding questions are ‘problem solving’ questions: the interviewer tells you a problem, e.g. identify all the words, which, by changing one letter, can become a palindrome. You usually have ~45 min to solve it.

I would start by asking clarifying questions, e.g. what’s the form of the input — is it already split into a list and each item is a word or do I need to parse it myself; or, by ‘changing’ what do you mean — can I delete or add letter or can I only replace a letter by another one, etc.

Then I’ll start from the brute force solution: ‘I’ll first write a function to identify palindrome, i.e. return True/False given a word, then write another function to loop through all letters of a word and given each letter, try to change it to each of the other 25 letters, and use the first function to determine if the new one is palindrome’.

Clearly it works but it’s way too slow, so usually you won’t write that out, but instead you’ll start to think about ways to improve it. Then I would suddenly recall that, for any string-operations problem, a typical solution is to use ‘pointers’ — this is something you’ll know once you have gone through enough Leetcode problems (themes start to emerge!). I would use 2 pointers, i and j, and a macro variable to keep track of the number of ‘differences’. i starts from the first letter and j from the last, and in each iteration, if i and j are the same letter I move i one position to the right and j one position to the left; if they are not the same, I increase the macro variable by 1, and let i and j move to the next position. At the end, if the macro variable is only 1, it means there’s only 1 difference, and this word can be changed to palindrome by changing 1 letter; otherwise it can’t.

And at the end you should run a few test cases to show that your function works and/or debug by test cases — you’re almost never bug-free the first time!

There’s another completely different type of coding interview where you’re given a dataset, e.g. some user pre-existing characteristics and results of an experiment, and you’re asked to answer a few questions by plotting graphs / running regressions. That should be easy for econ phd because that’s what we do everyday (except for theorists…?) But the only problem is that — you need to do this in Python or R, instead of Stata. So get comfortable doing the same thing you used to do in Stata with Python pandas or R’s equivalent package.