I failed an interview because of an algorithm
Tags: interview, job, career, tips
Published: 2020-08-16 11:57:36

<blockquote>
<span>Photo by <a href="https://unsplash.com/@siora18?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Siora Photography</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>
</blockquote>

---

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!

## Table of content

- [Stage 1: Getting an interview](#stage-1-getting-an-interview)
- [Stage 2: Human Resources (aka HR)](#stage-2-human-resources-aka-hr)
- [Stage 3: The managers](#stage-3-the-managers)
- [Stage 4: the HR (again)](#stage-4-the-hr-again)
- [Stage 5 (latest): The devs](#stage-5-latest-the-devs)
  - [About me](#about-me)
  - [Technical questions](#technical-questions)
     - [JavaScript questions](#javascript-questions)
     - [CSS questions](#css-questions)
     - [HTTP questions](#http-questions)
  - [Technical Challenge](#technical-challenge)
  - [After the test](#after-the-test)
- [The last HR Call](#the-last-hr-call)
- [Thoughts about hiring X our skills](#thoughts-about-hiring-x-our-skills)
- [Learnings](#learnings)
- [Conclusion](#conclusion)

---

## 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](https://www.raulmelo.dev/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 these questions, they constantly asked me to give examples of it, some situations I have been passed that prove I think or solve a problem in the way I was doing.

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 passed 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 flavor, 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 prove that, I'll go until where's needed to defend that.

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;
1. 30 min to answer and explain technical concepts;
1. 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 https://dev.to/sarah_chima/var-let-and-const--whats-the-difference-69e %}

---

##### 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`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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 https://dev.to/benjaminmock/const-seal-freeze-immutability-in-js-2m77 %}

---

##### Can you explain what DOM is?

I think that was the easiest one, despite the fact I forgot what the acronym means (**D**ocumment **O**bject **M**odel).

{% post https://dev.to/sukhbirsekhon/dom-tutorial-39n %}

---

##### 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 https://dev.to/jsm91/event-propagation-in-three-parts-4h9 %}

---

##### 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 https://dev.to/paulryan7/event-delegation-what-is-it-and-why-should-i-care-2e7j %}

---

##### 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](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) 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 https://dev.to/digi0ps/creating-animations-in-javascript-using-requestanimationframe-11nh %}

---

#### 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 https://dev.to/phuchieu/css-display-property-4nai %}

---

##### 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 https://dev.to/smeet_j/css-basics-layout-fundamentals-block-inline-inline-block-464h %}

---

##### 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 https://dev.to/flores8/how-to-vertically-align-anything-with-css-i78 %}

---

#### 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 https://dev.to/flippedcoding/difference-between-those-http-requests-2m13 %}

---

##### 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](https://httpstatusdogs.com/) which it's an amazing way to understand each code. 😁

{% post https://dev.to/bearer/the-http-status-codes-you-need-to-know-1kd %}

---

### 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](https://codesandbox.io/) with a single JS file:

```js
// 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

```js
// 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:

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

And it passed! :)

Then I had to solve the second assertion:

```js
// index.js

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:

```js
[
  '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](https://stackoverflow.com/a/6832706) 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](https://www.codewars.com/), [FreeCodeCamp Learn](https://www.freecodecamp.org/learn) and [Codility](https://app.codility.com).

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!