Showing posts with label Coding Interview. Show all posts
Showing posts with label Coding Interview. Show all posts

Sunday, February 24, 2019

Coding Interview: The Game Plan

I am doing interviews few times a year, and it's probably not enough[1]. Opportunities aside, I learn a valuable lesson every time.
Interview pressure uncovers weaknesses. Mine are overcomplication, impatience and panic:
  • I somehow expect the problem to be hard. So, I dismiss valuable cues and intuitions if they look too obvious.
  • If I feel a hunch, I dive in without full understanding. I keep stepping on this rake... and solving a wrong problem!
  • I the problem sounds intimidating, I panic and freeze, not knowing where to start.

Brute-force

To compensate for these weaknesses, I now start with a simplest solution that comes to mind. I work on a naïve solution first, clarifying my understanding, and then brainstorm ideas to improve it.
Structuring your work this way reduces the cognitive load when you start working on an improved solution.
This is an intuitive and well-recommended technique. However, I feel that candidates are afraid to look inexperienced and skip this step. As an interviewer, you may want to offer your candidate to start easy.
image

The Game Plan

It helps to mentally structure the interview into phases. The opening is important as it sets the tone, and brute-force can help you get through. Early phases are head-up: collaborate, learn and explore. Late phases are head-down: focus and deliver.
The game plan also helps manage your time and deliver a solution before the interview is over.

Sunday, January 27, 2019

Dynamic Programming: Minimum Travel Cost

The higher is the bar, the more you're expected to use dynamic programming (DP) during an interview. This technique requires a lot of practice to grasp; if you've mastered the recursion, DP is the next level.
This problem appeared on LeetCode weekly contest #121, and it's a good problem to practice the DP thinking.

Problem Description

In a country popular for train travel, you have planned some train travelling one year in advance. The days of the year that you will travel is given as an array days. Each day is an integer from 1 to 365.
Train tickets are sold in 3 different ways:
  • 1-day pass is sold for costs[0] dollars;
  • 7-day pass is sold for costs[1] dollars;
  • 30-day pass is sold for costs[2] dollars.
The passes allow that many days of consecutive travel. For example, if we get a 7-day pass on day 2, then we can travel for 7 days: day 2, 3, 4, 5, 6, 7, and 8.
Return the minimum number of dollars you need to travel every day in the given list of days.

Tuesday, July 3, 2018

Coding Interview: Pseudocode

"Interview is an artificial reality designed by companies to keep people out" - Manager Tools
Many companies won't offer helpful feedback on your interview performance. I think that feedback is a fair game, and the process should be transparent.

Pseudocode

This is a follow-up on the older post, Interview Insider: Coding fluency. A reader asked my opinion on using pseudocode to document his thoughts while working on the solution. Specifically during a phone screening, when diagramming may not be a possibility.
I want to start by quoting Steven Skiena's TADM[1]: