Why You Need an Interview Script

There are few things as anxiety-inducing as being interviewed for a job or as an assessment over coursework. It goes beyond merely stressful and creates a host of physical reactions: sweaty palms, shaky legs, labored breathing, a queasy stomach, and much more. All while your performance will ultimately determine your potential grades, salary, and career opportunities.

It’s no wonder that our ability to solve problems and answer technical questions degrades substantially under these conditions! And yet, many people brush off these concerns and hold onto an illusion of superior competence while under trial by fire. With so much depending on our ability to perform under stress, we should be smart about setting ourselves up for success and create a process to reduce this mental degradation while under pressure to perform.

That is why you need an interview script. Having a prepared script to follow will help you get into the flow of solving a problem before your anxiety can make you freeze and sink your performance. To illustrate its effectiveness, I’ll take you through a coding challenge using an interview script that I’ve created for myself and has helped me succeed in my assessments at Launch School.

Step 1: Read the problem and load it into your brain

First and foremost, you need to slowly read the problem and start processing it so that you can understand what you are being asked to solve. Start by writing out the problem’s main points in your own words.

Here is our code challenge:

Write a method that takes a string argument and returns a new string that contains the value of the original string with all consecutive duplicate characters collapsed into a single character.

Now, your first thought after reading may range from “This looks so easy!” to “Where do I even begin?”. Believe me, if you think this problem will be no sweat during an interview, that is the illusion of competence speaking to you. Every problem will seem more difficult when you are under the interview spotlight and can feel the gaze of your interviewer boring into you. Even problems that you may have handled with ease in the comfort of your home will suddenly morph into frightening monsters while under pressure.

Let’s take the prompt apart and write it out into something simpler to read:

- You are given a string argument for a method.
- This string may contain consecutive duplicate characters.
- Write a method that will take this string argument and return a new string.
- This return value will have all consecutive duplicate characters collapsed into a single character.

Include some examples of string arguments and the expected return values to illustrate what you want your solution to achieve.

Input: ‘bbbbbbbbb’ → Output: ‘b’
Input: ‘wwooonndeerrfull woorrlldd’ → Output: ‘wonderful world’

Great! This is more manageable and captures the main points, while also showing the interviewer how you can break down a problem into understandable parts. This will help to anchor you during the interview and serve as a reference while you craft your solution. The key is small victories along the way that demonstrate your skills and help you progress through the challenge while maintaining your confidence and flow. Breaking the challenge into smaller, manageable pieces is the first victory.

Step 2: Write out your approach in a step-by-step process.

Our next step will be to carefully layout our process for creating the solution in a step-by-step process. Doing so will allow you to focus on each individual step one at a time, while also making it easier to see the flow of the solution. Additionally, once you’ve solved the problem and receive some questions regarding refactoring or extra features, you can more easily see where in the flow to make your changes.

Here is my step-by-step process template:

Approach:
(1)
(2)
(3)

Using this template, I write out my high-level approach to solving the problem and then list each step in the solution’s execution. Here is my completed template for this challenge:

Approach: Use a loop within the method to check each character in the string. In this loop, we will check whether the character is equal to the next character. If it’s a duplicate, we will skip it. If it is not, then we will add it to a new string. At the end of the method, we will return the new string.
(1) Write a method definition that takes a string argument.
(2) Initialize a local variable assigned to a blank string.
(3) Initialize a local variable called index assigned to 0 to track which character we are checking in the loop.
(4) Create a loop that starts at index = 0 and repeats until index = string[-1].
(5) For each loop execution, check if the current character matches the following character.
  (i) If true, increment the index and start the next loop execution.
  (ii) If false, add the current character to the local string variable.
(6) Once the loop is complete, return the local string variable containing the string of distinct characters.

Phew! That may seem like a lot of writing, but it will make crafting the actual solution much faster and it will help you to answer any curveballs the interviewer may throw at you later. Another victory achieved!

Step 3: If no tests are provided, write some out with your expected output.

Remember, good engineers test their code! Your interviewer may provide you with some tests, but be prepared to write some yourself. Here are some tests that I would write for this problem:

collapse(‘bbbbbbbbb’) == ‘b’
collapse(‘wwooonndeerrfull woorrlldd’) == ‘wonderful world’
collapse(‘222xyzxyzyx’) == ‘2xyzxyzyx’
collapse(‘Q’) == ‘Q’
collapse(‘AAbbCC’) == ‘AbC’
collapse(‘’) == ‘’

Do not take this step for granted! It is a vital component in the process to show your value as a strong applicant. An engineer that thoroughly and consistently tests their code will stand out among other applicants, and the best places to work highly value good testing practices.

Step 4: Layout your rough draft of the problem with pseudocode.

At this time, we can start writing out the skeleton of our solution. Start with the basic method definition, and then write out the steps from your approach in your solution. Note: you should prioritize completing a working solution, even if it is a brute force solution with some redundancy. Once it’s finished, you can and should refactor your code.

def collapse(string)
INITIALIZE A NEW EMPTY STRING VARIABLE collapsed_string
INITIALIZE index AT ZERO.
while index <= string[-1]
START WITH FIRST CHARACTER AND EXAMINE NEXT CHARACTER.
if THEY ARE THE SAME,
INCREMENT index BY 1
SKIP TO NEXT CHARACTER FOR LOOP.
else
ADD CURRENT CHARACTER TO NEW STRING VARIABLE.
end
INCREMENT index BY 1
end
RETURN collapsed_string
end

Now, this step may seem extraneous considering that you already wrote your steps out in the template above. However, using pseudocode to outline your solution is like writing your first draft of a paper. It provides the skeleton that you’ll flesh out moving forward, and there is already some code written. Remember, small victories along the way will keep you in the flow and prevent your confidence from wavering under the spotlight.

Step 5: Rewrite solution in actual code.

Now take each line of pseudocode and replace it with actual, functioning code.

def collapse(string)
collapsed_string = ‘’
index = 0
while index <= string.length
if string[index] == string[index + 1]
index += 1
next
else
collapsed_string << string[index]
end
index += 1
end
collapsed_string
end

No sweat right? At this point, you have been running a consistent train of thought on how to solve this challenge and avoided freezing up.

Step 6: Test your code.

Now it’s time to test! If given the chance to use a computer, run your tests and see if they all pass. If you’re on a whiteboard, go through some tests by hand to make sure that your solution executes as expected.

If you encounter any issues, this is a good thing! You’ve shown that you are willing to check your code and can handle fixing bugs. Remember: very rarely does ANY code work on the first run and it’s completely normal to undergo a few revisions before a successful run. It’s more important to show that you are comfortable with the process of creating, testing, and refactoring your code to completion, and will do so with any code you work on.

Step 7: Refactor your code.

So now you’ve gotten all your tests to pass and you’ve cleared the challenge. Awesome job! But it doesn’t stop there, and you will likely be asked by your interviewer if you can refactor your code to improve it. Hopefully, the previous steps have given you an in-depth understanding of the problem and your own solution to easily identify areas of improvement.

Let’s go through our code and look for areas to refactor:

def collapse(string)
collapsed_string = ‘’
index = 0
while index <= string.length
# condense conditional into a single line using “unless”
if string[index] == string[index + 1]
index += 1
next
else
collapsed_string << string[index]
end
# remove redundant “index += 1” line
index += 1
end
collapsed_string
end

By condensing the if else conditional into one line with the ‘unless’ keyword and removing the redundant ‘index += 1’ line, we can shorten our solution by 6 lines!

def collapse(string)
collapsed_string = ‘’
index = 0
while index <= string.length
collapsed_string << string[index] unless string[index] ==
string[index + 1]
index += 1
end
collapsed_string
end

And there you go! We now have a more compact and readable solution with just a bit of refactoring.

Step 8: Handle any curveballs.

It’s no secret that once you’ve solved and refactored the initial problem, your interviewers will likely ask how you would modify it to handle a new scenario. This is another reason why we’ve taken such a detailed approach to solving the problem, as you’ll be much more comfortable with the conditions of the problem and can adjust to these curveballs.

Potential Curveballs:
(1) What about a string that’s a mix of upper & lower case letter? Ex: ‘AaABBb’
(2) What about an invalid input, like integer values? Ex: 1234
(3) What about a mix of string characters and integer values? Ex: ‘AbC’45’deF’

These can be addressed either through refactoring your solution or using exceptions to handle invalid input. I’ll leave these as an exercise for the readers to attempt for practice. By this point, I hope that my script has gotten you into the flow of solving this challenge and made you feel confident about handling these curveballs.

Practice and Improve the Script

Now that you have the script, you need to practice using it in order to reap the maximum benefit from it. Incorporate it into every coding problem you face, no matter how simple it may seem. While the steps laid out above may help you solve difficult problems, it’s main purpose is to anchor your thinking, maintain your flow and confidence, and fight the mental degradation during an interview or assessment.

The more problems that you complete using the script, the easier it’ll become to get started solving a problem while under the pressure to perform. In fact, I believe that it will help you stand out among other interviewees who don’t have a practiced script and end up floundering around a bit before making any progress on the problem. Every inch counts in your interview and against your competition, so make use of this script because I can assure you that there will be others who won’t.

Note that this is the script that has worked for me thus far, and I will improve upon it as time goes on. You should make your own modifications that suit your style, whether it’s creating your own step-by-step process template or how you initially identify the main points of the problem. Just make sure that you follow the overall process and methodology of the script, which is breaking down problems into smaller, digestible pieces that you can manage while under pressure and will earn you small victories along the way.

Conclusion

I hope that this script proves useful to you in your future interviews and assessments. If you have any additional points that I may have missed or a particular technique/step that you have found helpful in your own problem solving, please leave a comment below. I’m interested in hearing your thoughts and experiences and look forward to the discussion. Thank you for reading!