Common Algo Problem Solutions
github.com
github.com
LeetCode:
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers x and y, calculate the Hamming distance.
Yours:
1)Hamming Distance The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance.
Another one, LeetCode:
Given an array of integers, every element appears twice except for one. Find that single one.
Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Yours:
2)Single Number Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
I wonder if there's a way to make money from cheaters caught in the act. The only thing I can think of is making reimbursement of travel expenses conditional on not cheating. Or encouraging them to somehow gamble money on the assumption their solution is correct.
Just using unconventional language to describe the solution could be a good signal: People learning something new often use the same words as the source material.
You would certainly save money.
Your argument reads a bit like a conspiracy theory to me, but it's definitely one of the more fun and reasonable ones I've read. :)
I was personally wondering why the "find duplicates" algorithm multiplied every number by -2. Maybe there is some reason, but I don't know what it could be.
I don't get this anti-worker attitude. However I'm not surprised to see it on HN
In practice recent prior exposure to the problem and possible solutions makes answering such a question far easier, so the most prepared for the questions wins. They don't test thinking, they test preparation.
This happened to myself (although in a non-interview situation):
In general, if you have solved many problems and looked at many solutions, you simply won't remember each specific problem. This effect may start as early as your first math olympiad, and will only get worse on university while you study math and/or computer science.
Some time ago I solved a math puzzle, where I got the right ideas relatively quickly, even though I was convinced this problem was new to me. Later I found out in my writings that I actually solved exactly that problem some years ago.
Even though I was unable to remember the exact solution, not even remembered I've seen it before, I seem to have internalized enough clues so I could rediscover the exact solution whenever I need it.
Wait, practicing problem solving is somehow "cheating"?
So we have an industry where a handful of SV companies have found that algorithmic parlor games are an indication of good hire vs bad hire. The rest of the industry has simply decided to mimic this practice with reasoning that goes "if Google's doing it it must be the right thing to do.", with no thought that Google's reality has so very little to do with their own.
So now that algorithm challenges are the bog standard for interview it would stand to reason that you would best yourself by studying or practicing some example problems. B that somehow is considered "cheating." So you are either born with these skills or you are not is that correct?
That is patently absurd.
So to weed out those who obviously did some studying we should seed the internet with misinformation in order to catch these "cheaters"? Is the thinking - if you weren't born with the skills to write a function to "search for the missing integer in a matrix that has been rotated by k elements" you probably aren't a good programmer?
For example, the rotate array is much better handles with a deque; you get amortized constant time rotations.