So what went wrong?
Why? Because when I asked him what kind of data structure I might expect as input for this example of data: [['grapes', 1], ['apples', 0], ['peaches', 1]], he replied 'arrays only'. That was a first strike for me. Java doesn’t allow arrays of mixed types, but that was exactly what he was asking me to do.
However, my explanation wasn’t enough the first time. Then I asked him a second question: what should be the length of the array representing a basket? There’s nothing wrong with an answer like his – “More than 3” – if you’re using some other language rather than Java (and some others), because in Java, the array length is deterministic and must be predefined during declaration!
I had to explain to him that it is not possible in Java to create an array with an indeterministic length; we have to use the List interface instead.
Only after that, the interviewer recommended me to use the List interface. I understood at that point that he might be a professional developer, perhaps using other languages, but the basics...
So, I had to explain to him that we must (if he didn’t want to use abstraction in the example I described above) use the Map interface if he insisted on keeping that structure: ['grapes', 1].
Eventually, he was convinced, and I started the implementation.
A customer comes to the store to buy some products. They can buy apples ($3), grapes ($5), and peaches ($7). There are also two types of discounts:
Calculate the price of the basket, taking into account that data comes in the following format (I apologize for the exact numbers; I am reproducing them following the logic the interviewer tried to explain to me, which remained in my memory):
[["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
The following metrics were computed from 14 interview experiences for the Shopify Software Engineer role in Ottawa, Ontario.
Shopify's interview process for their Software Engineer roles in Ottawa, Ontario is extremely selective, failing the vast majority of engineers.
Candidates reported having very negative feelings for Shopify's Software Engineer interview process in Ottawa, Ontario.