Usually the issues companies throw at their applicants aren't that difficult to solve. Every dev should know how to split data into structures you can work with.
Google asked me a question… I could solve it in O(n²) but not in O(n).
After, with calm, talking about it with a friend who is a professor at university and has a phd in mathematics, he reflected that since my problem only used positive numbers, I could have exploited a certain property and simplify my algorithm.
So in the end, if you're lucky and have faced that particular completely artificial problem before, you can do it.
Otherwise you need some calm to think, and you can't do that while there are two people harassing you because you named your variables with a name they don't like, and a clock is ticking.
In the end you're selecting for "has this person heard of this problem or a similar one before" and not "can this person think".
These kind of tests are rarely about seeing if an applicant can actually successfully solve the issue. It is about seeing how the applicant approaches a difficult problem.
Maybe google, amazon and whatnot see that differently but I would not personally wanna work there anyway.
After, with calm, talking about it with a friend who is a professor at university and has a phd in mathematics, he reflected that since my problem only used positive numbers, I could have exploited a certain property and simplify my algorithm.
So in the end, if you're lucky and have faced that particular completely artificial problem before, you can do it.
Otherwise you need some calm to think, and you can't do that while there are two people harassing you because you named your variables with a name they don't like, and a clock is ticking.
In the end you're selecting for "has this person heard of this problem or a similar one before" and not "can this person think".