Shopify: who interviewed me for the Staff Engineer position? Junior?

Surely many people know Shopify - its network is quite large and as of yesterday it was positioned by the No. 8 company on the LinkedIn network (according to the rating of employers, if I am not mistaken).

One fine day, I saw their Staff Software Engineer position in Ottawa, and remembering that the guys work, including with big data, and accordingly with machine learning, which I frankly miss after working at IBM, I leaned on this position.

The interview is fairly standard - first, a 15-minute call from the recruiter to make sure I am alive or not, then an hour-long story “for life” with another recruiter, and then a brief task for 20 minutes, which is a kind of barrier, eliminating well absolutely unreasonable probably.

By the way, exactly a year ago, in May 2019, I also interviewed them, went through all the above steps, but received a more delicious offer from another company, which is 5 kilometers from the house, while in the Shopify office it was necessary go to downtown, and this is about an hour, and parking there is not cheap. And precisely because last year I liked both the process and the adequacy of the employees - I decided to go again.

But at some point, something went wrong.

It all started with the fact that the task that I was asked to solve was as follows:
The buyer comes to the store to buy products. He has a basket where he can put something, and the store wants to further stimulate the buyer by providing him with additional discounts on goods:

1. If the buyer buys more than one apple, he will receive a 20% discount on all apples in the basket;
2. If the buyer buys a package of grapes, then the second package he will receive for free.

Bottom line: calculate the cost of the buyer's basket when leaving the store, while the data is given in the following form:

[["grapes", 1],["apples", 0],["peaches", 1]] => 12
[["grapes", 1],["apples", 1],["peaches", 1]] => 15
[["grapes", 1],["apples", 2],["peaches", 1]] => 16.8
...
[["grapes", 3],["apples", 1],["peaches", 1]] => 20

where the first element of the nested array is the name of the product, and the second element is the amount of the product of this type in the basket.

Food prices are as follows:
- apple ($ 3)
- grapes ($ 5)
- peaches ($ 7)

I said OK, the interviewer asked which language I would prefer, to which I answered “Java” and began to evaluate the task.

My first question sounded innocent:
What data structure should I expect as input?

The answer was even simpler:
Arrays (arrays). Create an additional method and describe the data there manually.

Well, I thought, since we are not looking for easy ways, and also considering that the interview is still in the position of Staff Engineer, they most likely want to see me implement using abstraction and generics, something like this:
class Values<T> {
   T data;
   Values() {}
   Values(T data) {this.setData(data);}
   public void setData(T data) {this.data = data;}
   public T getData() {return this.data;}
}

and their use:
public class Main {
   public static void main(String[] args) {
      Values[][] item = new Values[3][2];
      item[0][0] = new Values("grapes");
      item[0][1] = new Values(1);

      item[1][0] = new Values("apples");
      item[1][1] = new Values(1);

      item[2][0] = new Values("peaches");
      item[2][1] = new Values(1);
   }
}

and since we were on a shared resource, I asked an innocent question, but how to create an additional class, because I really did not want to use Static, and it seems like it is not useful in this case.

I was a little surprised when I heard an answer like - “Why? Just use arrays and everything, why complicate everything? ” I specifically asked again about arrays - exactly arrays? The answer was unchanged.

Well, arrays, so arrays, albeit with static classes then, since the excitement began - the task was not as simple as it seemed at first glance.

The second question, in fact, stemmed from the first:
What is the expected data size?

Hold on ladies and gentlemen, for the answer was cool:
Size may vary, but not less than 3 elements.

Sorry? Of course, I can create an array with data dynamically, where there will be a parameterized variable as the length of the array, but I need to know how many objects I will need to insert into the array - after all, having created the array once, I cannot change its length. Therefore, here I had to literally explain to the interviewer how arrays are created inside the JVM, why their size is fixed, and why their length cannot be redefined after creation - only creating a new one and copying the data.

At that moment, when I was explaining the basics of "mass building", I mentioned the List interface and said that for example ArrayList, as one of the implementations of the interface, although it is based on arrays inside, but allows for dynamic size.

The interviewer was a little thoughtful and said, “Great, then use an ArrayList and insert the data there.” By the way, it took about 15 minutes until we all figured out this and I explained to him about the arrays (in total an hour was given). I asked how to insert, whether we use generics already or not - nothing has been written yet, but if we continue to go at such a pace, then you might not have time.

The interviewer issued another pearl, after which I realized that it was a trumpet. He simply wrote the following on a common board:
"Grapes" => 1st element
1 => 2nd element

Probably my moan was even audible, but I had to ask him a question - my dear man, how can I insert heterogeneous data into an ArrayList without using abstraction and generics? I must declare the data type when creating the structure. Well, do you really want me to use Object and continue to do casting everywhere, depending on the position of the element?

His naivety struck me - "But is it really impossible to insert string and numeric data into a sheet?" I say, yes, of course you can, but either with abstraction and generics, or Object and typecasting, or not in Java, but in JavaScript, for example. Then I could not stand it myself and suggested, well, let's at least convert the numbers to string variables - less work, if you insist on ArrayList, but continue on - can you still use the Map interface?

The interviewer, although not immediately (I did not begin to find out the reasons, to be honest - there was about 25 minutes left), agreed and said - let's go to Map. I spent 10 minutes to throw the code skeleton, checked the boundary conditions and said that I had finished.

It turned out not to be there, and all the most interesting was ahead. Remember the discounts? I will quote the condition again:
If customer buys one grapes he gets another one for free. (If the buyer buys one package of grapes, he will receive the second for free).

In this case, we can assume that having data in the format:
["grapes", 2]

in the amount of this product can be taken into account and free grape packets. Then the picture should be as follows:

1. The buyer bought 1 package of grapes and received 1 for free. The result - in the basket 2 packages.
2. The buyer bought 2 packages of grapes and received 2 for free. The result - in the basket 4 packages.
3. The buyer bought 3 packages of grapes and received 3 for free. The result - in a basket of 6 packages.

Did you notice the pattern? In the basket of grapes there should always be only an even amount. However, based on the initial data, there is also an odd amount of viograd in the basket:
[["grapes", 1],["apples", 0],["peaches", 1]] => 12
[["grapes", 1],["apples", 1],["peaches", 1]] => 15
[["grapes", 1],["apples", 2],["peaches", 1]] => 16.8
...
[["grapes", 3],["apples", 1],["peaches", 1]] => 20


In this case, let's proceed from the opposite - since there may be an odd amount of grapes, then only the grapes that the buyer paid for are taken into account in the basket. Is it logical? It seems so. Options when the buyer simply did not take the free grapes are not considered.

And now attention is the right answer!
1   + 1  + 1 

This is enchanting! How? Well, how could that be? Yes, I don’t know everything, but I may have spaces, but explain to me - how can this be, based on the conditions of the problem !? I tried to explain something to him, but honestly - I just saw a void of misunderstanding of what I was talking about in the eyes of the interlocutor.

Everything is simple - in front of him are the numbers that he came up with and calculated on the one hand, on the other hand - what I gave. Mine are different, so what is the answer? My wrong ones - he's an interviewer and his decision seems to be right. In general, I spat on this matter, I was already angry from the situation itself, as I expected something more intellectual (which is why I look around to find a position where there will be more interesting tasks), but it turned out ... what turned out to be. I decided to abandon this position, but while writing my feedback, I received a rejection from Shopify.

I still sent my feedback to them with comments that the guys thank you for refusing, I’m afraid that I still couldn’t work with you and described the situation in the interview, recommending that it’s better to prepare for the interview even on simple tasks that, as you know, are not simple.

That’s the whole story. Take care of yourself and all the best to you.

All Articles