DEV Community

Discussion on: I failed an interview because of an algorithm

Collapse
 
luiz0x29a profile image
Real AI • Edited

You didn't failed because an algorithm. Array.sort() is fine for the task.
You failed because you don't know how to use sort when the data isn't a single atom. You need to know how to sort by weight.
Sorting is such a basic usage. If you didn't knew that you could at least format the strings as "005002001", "001000000", so they would be sorted and that would be a valid solution.
No, developers don't need to know how to implement BubbleSort, but you need to be able to use it effectively, and you failed on defining the problem.
I wouldn't fail a candidate solely on this, but I expect them to not go randomly trying to create algorithms, I would let them google for the solution if they at least explained the problem, I expect them to understand the problem, its not about going doing things and trying to make the test pass (I use DDD, not TDD, you would immediately fail for that reason alone, the way you solve problems).
And the problem was sorting by the version, you can either pass a comparator for version, or convert version to a normalized string or even to a integer, either way of solving the problem would be valid.

Heck, even giving up would be a fine answer if you understood that you needed to sort by the version and didn't knew how to.