Count the 1’s in the binary representation of a decimal number

As I wrote here before, I do a lot of professional interviews, and I discovered that the best questions have more than one solution to them. While having an ideal solution to a problem, you can still ask the interviewees for other ways for the solution and putting extra constraints that can help guide them in either direction (maybe to check their creativity, or if they knew the question beforehand). One of the questions that fit this requirement is the “count the 1’s in the binary representation of an integer”.

(more…)

Interview Question: Select only Prime numbers from table

As part of my daytime job, I conduct professional interviews for candidates. For that, I’m always on the search for good interview questions. I regard a good question if it’s not too complicated, has a number of ways to solve, and if needed, can be solved programmatically with SQL or C / C# / JAVA languages.

Now that I’m done with asking the prime number question (I need to change questions every now and then), I thought I will post the solution here.

(more…)