A Technical Interview Example: Problem and Solution

Sam Hall
5 min readAug 30, 2021

I don’t know about you, but I’ve been sweating at the idea of a technical interview in the months since I’ve finished my coding bootcamp. Well, I’ve just had my first technical interview and… it wasn’t so bad! This was a first round interview with very basic data, prompt and deliverables but I found the experience enlightening nonetheless. I wanted to share a similar example using JavaScript that I composed based on the information and deliverables provided to me by a potential employer.

The Data

Here is an array of objects that I created to give you an idea of what I was provided:

Here we have an array of objects “elevationData”, each with a state’s name in the form of a string, and a high and low elevation integer values. For the sake of simplicity I included Midwestern states with no negative sea-level values.

Deliverable 1

Deliverable #1

In this first deliverable, we must write a function that iterates over each object in the array, finds the highest elevation integer value, and returns the string indicating the state with that elevation.

Solution

As I said, we will need to iterate over each object in the array and read each integer value to find the highest elevation. To do this, I first set two variables “state” and “elevation” using the keyword let which limits the scope of the variable to the specific block of code that it appears in. “State” will have no value yet, and elevation will be 0 until replaced by the highest elevation in the dataset. I then employed the .forEach JS enumerable to loop over each object.

I used dot-notation on “data” to read each “high” elevation value, and a conditional using the keyword if to set our elevation variable to any number higher in value to what elevation currently is. “Elevation” begins at zero, should first replaced by Texas’s high value of 8751, and shouldn’t be replaced by any other number, because that is the largest number of any “high” value in our array of objects. We then have to set the variable “state” to the state string within the object with that elevation value, and return the variable “state” outside of our loop. Let’s see what the console.log returns:

Et voilà! Our function returns the string “Texas,” the object with the highest elevation value.

Deliverable 2

Deliverable #2

In the second deliverable, we must write a function that returns the string indicating the state with the largest disparity in high and low elevations (Spoiler: it’s still Texas). This function will be very similar to the one we wrote in the first deliverable so in my intermediate opinion, I suggest you ⌘C + ⌘V.

Solution

We still need to set variables using let for “state,” but this time we should declare another one for “elevationDif.” I employed the same .forEach loop in my solution, as well as an if conditional but with some slight code tweaking thereafter.

Now “elevationDif” will only be replaced by the difference of the highest and lowest values for each object.

The second function successfully returns the string indicating the state with the largest disparity in highest and lowest elevation: Texas. Everything’s bigger there, apparently.

Deliverable 3

Deliverable #3

This deliverable will need a function that takes two arguments: the array of objects “elevationData” and “state.” We will also need to set a unique variable within the function (I chose the distinctly different “stateName”) to set it apart from the parameter “state,” so as not to confuse our machine. We will also need to set variables “high” and “low” within the function to draw out those values and string interpolate them into our final elevation statement.

Solution

When iterating through the array of objects, we first need to check whatever is provided for the parameter “state” against the string values for “state” in the array (in this case I chose my home state of “Oklahoma” — howdy!). We must use “===” or the “strict equality operator” or “threequals” here so that our boolean result is accurate. This should stop the iteration at the object whose string value for state matches the parameter, and draw out both elevation values for “high” and “low” accordingly using dot-notation. We must then “string interpolate” these values into the elevation statement that we want our function to return.

I know my tense was out of whack throughout this blog. My apologies. I’m very tired.

Further Reading

I used repl.it for all examples.

--

--