# An Approach to Technical Interviews

The technical interview process can feel like a daunting challenge for a new developer just beginning to dip her toes into the industry. Luckily for me, I recently had the good fortune of connecting with a wonderful developer, Abby Tiffany, who talked me through a great framework to reference in future technical interviews.
Side Note: I connected with Abby after hearing her awesome episode as a guest on Lauren Lee’s podcast We Belong Here: Lessons from Unconventional Paths to Tech. I would highly suggest giving it a listen!
For this blog post I will be walking you through an example technical interview problem and talking you through the steps Abby outlined.
Our example problem: Given an array, remove any duplicate values and return an array that contains unique values.

Step 1: Reiterate the Question

Before diving into the problem being presented before you take a few minutes to think about what is being asked and repeat it back to your interviewer. You may have heard the interviewer ask one thing but the intent of their question might be entirely different.

Step 2: Clarify your Assumptions

This is your time to ask clarifying questions! Don’t assume that you have correctly interpreted the interviewer’s question and expectations.
Example questions can include:

When you say to remove duplicate values do you mean such that each element only appears once? Or should any value that has appeared more than once be completely removed from the array?
Will my input always be an array?
Will I ever be given an empty input?
What should my code return if the target is not found?
Should I treat a -1 equal to a 1?
How should my code treat input with a single item?
Is the input sorted? If so – descending or ascending order?
Should the array be updated in place?

Step 3: Create Test Cases

Now that you have an understanding of the problem itself and the input/output that you should be expecting take the time to write down a few tests cases that you can utilize to proof check against. Ideally, your test cases will cover a variety of different inputs (ex: expected input, empty array, negative numbers/etc).
Example test cases could include:
Test case 1: [0,1,1,4,9]
Test case 2: []
Test case 3: [-1,0,1,2,2,2,3,10]
Test case 4: [1]

Step 4/5: Discuss/Execute a Brute Force and/or Optimized Solution

In an ideal world you should be able to speak to a brute force solution and execute your optimized solution on the whiteboard. However, there are going to be problems you run into that are just hard. Maybe you can only think of the brute force solution – in that case execute the brute force solution and talk through how you would think of approaching it differently or optimizing it on a next iteration. Keep it mind that you should only be writing down either a brute force or optimized solution. You will not have time or whiteboard space to do both.
Now you may ask – but why would you discuss the brute force approach if maybe you know an optimized solution off the bat? Interviewers want to know what you know and they can’t know it unless you speak to it. Being able to speak to both approaches shows how much you know and that you did not just memorize the answer to a problem.

Brute Force

A way to approach our provided example problem could be to iterate through each item in the array, compare it against every other item in the array and delete any duplicates.
This approach would definitely meet the requirements of the problem however it is not the most efficient way for us to approach this. Comparing every item against every other item would result in a time/space complexity of o(n2) as the worst case scenario would be asking the computer to compare every permutation within the array. We can definitely do better!

Optimized Approach

A better way of approaching our provided problem might look like the below:

Create a Hashtable (or Dictionary) with a default value of 0
Iterate through the values in the array
Check to see if the item you currently are looking at is already a key in the Hashtable
If yes, set it equal to nil (or any other value to reference for future deletion)
If no, add it as a key with a value of 1 to the Hashtable and move on!
Return your adjusted array at the end of the program

def remove_duplicates(arr)