Interview Questions for Programmers

Over the years, I’ve seen a number of blog posts relating to common questions that should be asked of programmers. Obviously, this is going to depend on exactly what position you are hiring for, but there are some good “gateway” questions that can be used to determine whether or not an applicant you are interviewing can … well … even program at all. If they even have the mindset that makes a good developer.

A common one I’ve seen tossed around is Fizz Buzz. The challenge goes something like this:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Now, to anyone who even has a basic understanding of programming, this is super simple to solve using a modulus operator. But apparently many people applying for even entry-level development jobs cannot solve this problem. According to the article linked above, even one “senior developer” took 15 minutes to solve this problem.

Earlier today, a friend posted something on Facebook that inspired what I think it another good, intermediate to difficult level programming question that also looks for pattern recognition. The relevant part of the post began by stating: “This year July has 5 Fridays 5 Saturdays and 5 Sundays.” There is the question! It would go something like this:

The month of July 2011 has 5 Fridays, 5 Saturdays and 5 Sundays. Calculate the next 50 times there will be a month that has 5 Fridays, 5 Saturdays and 5 Sundays.

Woah, so how to go about solving this problem? Well, look at a picture of July 2011. Notice something interesting about this month in relation to the question? This month has 31 days (the most any month can have), begins on a Friday and ends on a Sunday. And that’s the solution! It’s any month with 31 days that begins on a Friday!

With this in mind, it’s pretty easy to come up with a PHP solution:

<?php
$count = 0;
$num_found = array();

while(count($num_found) < 50) {
    $count++;
    $ts = strtotime("$count months");

    if(date("t", $ts) == 31 && date("N", strtotime(date("Y-m-01", $ts))) == 5) {
        $num_found[] = date("F Y", $ts);
    }
}

print_r($num_found);
?>

Note that I make use of PHP’s strtotime function, because it is the Swiss Army Knife of date manipulation in PHP. This would need to be adapted for use in another language.

So now tell me: what are some other questions you’ve been asked or asked in an interview?

Comments (0)

Interested in why you can't leave comments on my blog? Read the article about why comments are uniquely terrible and need to die. If you are still interested in commenting on this article, feel free to reach out to me directly and/or share it on social media.

Contact Me
Share It
Randomness
So the good news is that things are stating to get better. The pandemic is starting to abate now that vaccines are widely available in the United States. Hopefully they will continue to be effective against the new strains that are emerging, and all evidence suggests that they are. Hopefully things will continue to improve around the world as well. Also equally good news is, with the pandemic abating, we can start to return to a more normal state. But many of us are emerging into a new world, one where it is basically impossible to buy a house because demand for houses is outpacing supply and where the costs of many things are going up due to scarcity. One of the interesting things I have noticed is that some businesses, and this seems to be predominantly fast food and restaurants, are having a hard time hiring people. Some have even shut down because they can’t find employees. What is happening here?
Read More
Randomness
I’ve been working from home occasionally for probably close to ten years now, and full-time for the last few months. Thanks to the COVID-19 pandemic, many more people are now getting to enjoy (I guess?) the privilege of working from their homes during the crisis. If there is one thing that I hope comes out of this whole miserable period it is the understanding that there are a lot of people out there have jobs that really don’t need physical presence in an office building. And if they don’t need to be in an office, maybe they don’t need to live in an expensive city either. This could be the beginning of a whole new boom for small and mid-sized cities with affordable costs of living. Maybe you can afford a house after all! And maybe companies don’t need to lease out an expensive building in an expensive city, fill it to the brim with people in open floor plans or (even worse) hot-desking to do the work they need to do. It’s an even bigger win for disabled and non-neurotypical people who often struggle to work in the modern knowledge workforce despite their skills. For people with autism, ADHD, and other related conditions, modern open offices or cubicles are a difficult work environment whereas the home environment may offer much more safety and control. If this is your first time doing this, it may seem a bit odd, even naughty, to be working without commuting to an office building. With that in mind, I’ve put together a list of things I have observed over the years of working from home to help you get a feel for what this is like.
Read More
Randomness
Those of my longtime readers will know that I very rarely if ever mention anything on this blog other than my Randomness on tech. But today is a very different day and I feel compelled to write about this. So I’ll ask for a mulligan. And, as always, my views here do not represent anything or anyone other than me.
Read More