• Home
  • Blog
  • I failed an interview because of an algorithm

I failed an interview because of an algorithm

This article was published on Aug 16, 2020, and takes approximately 15 minutes to read.

Hello, devs.

For the last couple of weeks, I've been participating in a hiring process for a big company.

It was a very nice experience and it gave me a lot of insights about hiring, code challenges, and how (possibly) to become more prepared for interviews.

As you already saw in the title, I didn't pass, but I went through all the stages of it. So it might be interesting for you if you're trying to get your first job, or even if you're thinking of switching jobs but don't do interviews for a couple of years already.

I'll explain all stages, with some details and thoughts, but my main focus here is to tell where and why I failed in the last part of it.

Hope you like it and I hope my experience can help you somehow!

Stage 1: Getting an interview

A very common practice in companies, in general, is to motivate people (with money) to recommend professionals to fill opening jobs (that's a good reason why you should build good connections as much as you can with people in and out of the internet).

A friend of mine recommended me to work in his company. Good salary, very well structured and it seemed a very good place to work in, why not try it out?
I just needed to do some adjustments to my online CV and I was ready.

Stage 2: Human Resources (aka HR)

The HR from the company just called me to know a bit about me.

They asked about all my experience, things I've done in my life, whether I had some specific knowledge (like React, testing, Redux, etc) and also questioned about the company I'm working on.

To be honest this call just seemed to be a filter for people who lied on their CV, because everything was very basic and trivial.

I was pretty confident in all the answers I gave to her, and at the end of the call she just gave me a positive feedback and then she'd schedule the next phase with the tech lead and team manager.

Stage 3: The managers

The following week, I had a 1-hour meeting (now with webcam) with the "managers".

Their job was getting to know about my soft skills. A lot of questions like:

  • What is the proudest moment of my career
  • What was the worst technical decision I have ever made
  • How I deal with conflicts
  • How I deal with top-down decision
  • How I handle hard discussions

And in between those questions, they constantly asked me to give out examples of situations I have experienced that exemplifies that I thought or worked out a solution in the way I was explaining.

It was very nice because I could remember some good and bad moments in my career which made me grow up a lot as a professional and also as a person.

When I turned the call off, I was still very confident about the final result.

After a couple of days, the HR called me saying the managers liked me and the way I answered their questions (maybe someday I can share in details some situations

I've been through and my current way to deal with people and job).

The only feedback she gave to me was: "I needed to be less of a follower".

And... of course, they thought I was more of a follower than a leader or something because, to be honest, I'm almost 30 and I kinda lost the energy to keep fighting pointless discussions about technical tastes and personal ways to code.

I have my opinions and I always can argue why I have them, but to be honest, when the discussion reaches the moment where it's an ego thingy or personal taste, I just give up and let people do what they want.

I do not care about:

  • what's the best JS framework;
  • what's the best state management library;
  • if we should use reduce or map + filter;
  • if we should use it or test in jest assertions.

I do care about:

  • what solution fits best for the problem;
  • good naming;
  • tested code;
  • a simple solution when it's possible;
  • ship the product;
  • my salary at the end of the month.

In the past, I used to have endless debates about what's best, what's the worst. Nowadays I still have these discussions but if I notice that we're not going anywhere, I just agree and live my life.

But of course, don't be a fool. If I'm convinced that some bad decisions are being made and I can argue that a different approach is better, I'll certainly pursue my vision for a better option.

From a company’s perspective, what's the most valuable personality? We can have a long discussion about this.

Stage 4: the HR (again)

The next phase was again a HR call and she asked me some questions the managers made to me the week before.

She wanted to see for herself my soft skills.

Well, I didn't lie in any of the questions I gave the same answers.

I also tried to explain why the managers thought I was more follower like and it seemed she had got it.

She gave another positive feedback and then told me the next step would be with 2 devs to test my hard skills and a QA manager would be present just to watch the process.

Stage 5 (latest): The devs

This one was the trickiest stage and I want to give you full details about how it went. I want to recommend to you guys some articles that might answer those questions if you don't know.

I received an email with some topics they could ask like JS, CSS, Testing, State management, React, and Http but still wasn't clear how they would approach those concepts.

It was scheduled to be 1h30m short but it started 10 min late.

When I joint the chatroom, as always we did some round presentation and they explained to me how it would work:

  1. 20~ min to get know about what I currently do;
  2. 30 min to answer and explain technical concepts;
  3. 30 min to do a code challenge.

About me

Here again, I had to explain what I do in my current job, but more technically.

Well, it's only me and another guy responsible for the entire web ecosystem so I kinda know what the product is and how things are structured.

I had explained to them in detail about what's the platform, my responsibilities, what’s my daily tasks to give to them an idea and how we're handling them, etc.

Sometimes they asked me to dive deeper in some topics but it was easy at the end.

Technical questions

Here starts to become a bit tricky because they started a certain quiz. I'll try to not dive deep into explanations and solutions but instead, just give my impression, a short idea about it and share an article explaining in detail those questions and concepts.

JavaScript questions

Can you explain the difference between var, let, and const?

It can be indeed tricky, especially if you have started learning JS recently. I believe people just say: always prefer const but if you need to reassign then use let.

Luckily I've passed the transition from var to let and const and remember clearly it's about scope.

To explain that I used the object mutation even when we use const, so they got a second question from here:

Post about it: Var, let and const- what's the difference?
How can you freeze an object?

I know this concept because I caused some bugs while learning ES6. After a few hours trying to know why my object was being mutated, I've found documentation about the native API Object.freeze.

It's very straight forward. When we freeze an object any operation which will mutate an object does not change the object itself. Be aware that this freeze only happens at a shallow level (1 object-level deep) and does not freeze objects and arrays nested.

Post about it: const 📦, seal 🤐, freeze ❄️ & immutability 🤓 in JS
Can you explain what DOM is?

I think that was the easiest one, despite the fact I forgot what the acronym means (Documment Object Model).

Post about it: DOM Tutorial
Can you explain how events propagate in the DOM?

I knew this question because before I learned React I've created my own JS framework (it was a nice experiment) where I learned a lot about capturing event in different levels and also how bubbling works.

Post about it: Event Propagation in Three Parts!
What's the advantage of using a single event to capture events?

It was still related to this question and to be honest, I wasn't sure.

I remember when I had implemented that in Vanilla JS where I had a form and instead attached onChange to all inputs, I just did in the form level and had some sort of switch to decide what information to update or what to do but... I've forgotten why this was good. My assumption was about performance.

The dev told me it was exactly about this and gave me a very good example. Imagine a table with thousands of records. If we attach a single event to each row we would have for sure performance issues because the DOM will have thousands of events to dispatch.

I really liked this example.

Post about it: Event Delegation - What is it and why should I care?
Do you know what the Request animation frame API is and why we would use that?

I think I've used Request Animation Frame (RAF) API once or twice in 5 years so

I was not sure why such API exists, then I tried a guess: “tell the browser that we're gonna do some animations and get some performance.”

They told me it was correct.

Post about it: Creating animations in Javascript using requestAnimationFrame

CSS questions

Do you know about the different displays?

Didn't get much this question. I wasn't sure if I needed to explain each display or just say: "yes, I know".

But my answer was saying I have a few displays we have like inline, inline-block, block, grid, flex, etc.

To my surprise, it's what they wanted to hear.

Post about it: CSS Display property
What's the difference between display inline and display inline-block?

This I didn't know by heart.

I knew the difference between inline and block because it's a very common thing to do in CSS but I couldn't remember the difference between inline and inline-block.

The dev explained to me that when we have inline-block we can define margin and padding to the element while in display inline we can't.

Post about it: CSS Basics Layout Fundamentals: Block, Inline & Inline Block
How can I center something vertically?

Also another tricky question and maybe because we have several ways to do that.

The way I know by heart is using display: flex combined with justify-content: center and align-items: center.

My answer was good enough.

Post about it: How to Vertically Align Anything with CSS

HTTP questions

Can you tell us what methods are available in HTTP?

Not that difficult since I sometimes play with backend in Node.

  • GET
  • POST
  • DELETE
  • PUT
  • PATCH

Then they asked me if I knew the difference between PUT and PATCH and that's tricky.

I remembered one replaced the entire data with the new content and the other just updated the information sent, but I didn't know which one did what.

They told me it was right but who does partial updates is PATCH and a full replacement is PUT.

On top of this question they asked if I knew about other methods, like OPTIONS and to be honest, I didn't.

Often I see OPTIONS requests in my network tab but I have never asked myself what hell was that.

Post about it: Difference Between Those HTTP Requests
How the HTTP status codes are divided?

Basic HTTP things.

I just remember that by heart because since I started building apps that consume APIs, I was curious to know what's the thing about these codes and I found this https status dogs which it's an amazing way to understand each code. 😁

Post about it: The HTTP Status Codes You Need to Know

Technical Challenge

I had the feeling I ruled the quiz questions and I was much ready for the technical challenge.

"30 min might be enough to solve something." I thought

Then they sent to me a link to a Code Sandbox with a single JS file:

index.js
/*
We have lots of deployment dashboards where we have drop-down UI to select
an application version to deploy. We want to ensure that software
version numbers delivered to our UI from the back-end API are 
always ordered with the newest (highest) available version at the top.

Eg:
const input = [0.1.0, 3.2.1, 2.2.3, 0.1.1];
sortVersions(input) should return [3.2.1, 2.2.3, 0.1.1, 0.1.0];
*/

const sortVersions = (unsortedVersions) => {
  // code
};

export default sortVersions;

And a test file with some assertions to ensure it was correct

index.test.js
import sortVersions from "./index";

it("should sort correctly numbered versions", () => {
  const versions = ["0.2.0", "3.1.2", "0.1.6", "5.0.0"];
  const output = ["5.0.0", "3.1.2", "0.2.0", "0.1.6"];
  expect(sortVersions(versions)).toEqual(output);
});

// Other assertions

Rules to solve that challenge:

  • I could use google to search about JS APIs
  • I couldn't use google to search for the problem specifically.

The first assertion was very easy. My solution was simply:

const sortVersions = (unsortedVersions) => {
  // code
  return unsortedVersions.sort().reverse();
};

And it passed! :)

Then I had to solve the second assertion:

it("should sort correctly numbered versions with different lengths", () => {
  const versions = [
    "1.3.0.9",
    "0.2.0",
    "3.1.2",
    "0.1.6",
    "5.0.0",
    "3.3.3.3",
    "3.3.3.3.3",
    "3.10",
    "0.2.0",
  ];

  const output = [
    "5.0.0",
    "3.10",
    "3.3.3.3.3",
    "3.3.3.3",
    "3.1.2",
    "1.3.0.9",
    "0.2.0",
    "0.2.0",
    "0.1.6",
  ];

  expect(sortVersions(versions)).toEqual(output);
});

And here I just got stuck.

My previous solution didn't cover cases like this. It just returned:

[
  "5.0.0",
  "3.3.3.3.3",
  "3.3.3.3",
  "3.10",
  "3.1.2",
  "1.3.0.9",
  "0.2.0",
  "0.2.0",
  "0.1.6",
];

And the reason is kinda obvious for simple string sorting. By default, it goes alphabetically where 3.3 comes after than any 3.1. But in semantic versioning, we know that 3.10 is greater than 3.3.

After playing around with sort methods, I had an idea about making all versions the same size based on the largest version.

To be honest, at that moment I was already nervous because I couldn't think in a way to solve that "simple" problem and consequently I started to get anxious.

I had some tips from them about how I could solve that but it was a bit hard to understand. Not because they didn't explain exactly but because I was trying to figure out many things at the same time.

While I was doing some code to make all versions in the same length, time was over.

The dev asked me if I had more time how would I solve that and I explained that my ideas were making all versions in the same length so I could compare per blocks.

I thank them for their time and we turned off the call.

If you're curious about how to solve this problem I recommend you take a look into this answer in StackOverflow. I just tested it and it solves all specs.

After the test

To be honest with you after I turned the call I felt myself a failure.

In the past 5 years, I've already solved so much harder problems than that and at the end, I was beaten by a sorting problem, what was wrong with me?

But I tried to comfort myself: "Ok... I went well in all previous steps, even when they asked me technical questions.. this shouldn't count too much".

The last HR Call

After a week waiting to see if I was approved I would be accepted or not, the HR person called me saying:

"Unfortunately we won't proceed with you"

I only could feel very frustrated.

Then I asked why and if I could have feedback about what I could improve and she told me:

"The devs really like your communication, your energy while doing the interview. They liked that you answered most of the technical questions correctly but they thought you didn't go well solving the last problem."
"hmm... ok", I said.

I could argue in many aways against this decision but let's be honest, the decision was made. It wouldn't change anything.

I turned off the call, stopped for 5 minutes to digest the feeling of failure, and tried to think about all this process.

Thoughts about hiring X our skills

I don't know if you already have had the chance to be the interviewer in your life. I had and I can say for sure: it isn't an easy task. And that's because the hiring process is very hard in general.

We need, somehow, to define steps and things to evaluate a candidate and despite our goal of being transparent and analytical, it isn't by far a perfect method.

People think, learn, solve problems, communicate differently from each other, and in a hiring process, we try to create some guides and filters that we expect about people.

It means that if someone just does not fit in what you expect, it might be a good signal that this person isn't ideal for the job. But... does it mean that this person would be a bad professional?

I don't think so.

I remember when I finally could get my first job as a developer, I made a similar code challenge and I just ruled that.

Do you want to know the difference between me 3 years ago and me now? At that moment I was constantly practicing solving algorithms in the FreecodeCamp platform.

After I got the job I proved myself a valuable employee and I can say for sure that the hard thinking I used to pass in the interview was not by far what made me ship product, because there were rarely moments I could not use Google to look how people solve this problem to create another solution on top of it.

I had some challenging problems to solve and I solved them all in a short or long time, sometimes with others' help, sometimes by myself.

To get my current job I had to create a React APP which consumes a public API, add tests (E2E), infinite scroll, animation between pages and host somewhere, explain my solution, my struggles, and do a pair programming to solve some problems I had.

And it's basically what I do most of the days to earn money.

Does not being able to solve an algorithm mean that I'm not a good developer?

I don't think so. In my mind, it just says I failed into solving a problem in certain conditions. But again, this is their metric of how to evaluate a professional.

My point here isn't to complain about why I was not hired but to make it clear for you that: failing in an interview does not mean you're a failure as a professional.

Learnings

Overall, doing all this process taught me a lot.

For the next interviews, I'll be prepared to easily answer questions about soft skills. I'll never forget the difference between inline and inline-block or what is the HTTP OPTIONS method and the difference between PUT and PATCH.

But my biggest learning was: try to be prepared for everything.

You might be requested to implement some APP using React, Vue, Angular, whatever, or even solving some tricky problems in JS.

For that, I already started spending few hours per day trying to solve problems in platforms like Codewars, FreeCodeCamp Learn and Codility.

While I'm still implementing new things on my personal website and get sharper in how to create a robust front-end application.

Conclusion

Hope my experience could give you some insight into what you could do differently to get your first job or at least to be prepared to rule a hiring process!