How would you program this?

In an interview last week, I was asked to write out a solution to a programming scenario. It was one of those “There’s no right or wrong answer, we just want to see how you think” type questions. But I have been thinking back to it periodically since then, and I’m curious what you all (much smarter people) would do.

Here’s the prompt:

Count up from 100 (start at 1). If the number is a multiple of 3, output “Dave.” If the number is a multiple of 5, output “Rod.” And if the number is a multiple of both 3 and 5, output “DaveRod.” If the number doesn’t fit any of those criteria, just output the number.

How would you code it, in the language of your choice?

Do a search for “fizzbuzz” and you’ll see all the solutions you could possibly want

Aha! I knew it had to be something widely used, I just didn’t know how to look for it.

As Thraeg said this is known as fizzbuzz. It’s really easy to program by using the modulus operator.

Gross.

A) there is totally a right answer for fizzbuzz.
B) personally, I would avoid any company that uses fizzbuzz in an in person technical interview, even for an entry level position*

* Mini-Rant: Fizzbuzz is a pretty basic “can you write code” type question, which is the kind of thing that should be pre-screened before asking a person to come in for an in person interview. An in person interview should be about gauging your personal interactions, culture fit, etc, or about more generalized problem solving that benefit from in person back and forth. Fizzbuzz style questions test neither of these things. Even as a basic code test though, Fizzbuzz is bad, because it’s testing your knowledge of a single programming “trick” (i.e. the modulo operator). It isn’t complicated enough for personal expression. Also, while not useless per se, basic math operations like modulo aren’t even relevant for a huge range of programming jobs. Modulo is something everybody should know, but not something it’s useful to test for.

Moreover, because Fizzbuzz is such a well known “interview question” paradigm, it’s paradoxically almost useless as an interview question. Like the “piano tuners” problem, what it mostly tests is “have you done enough technical interviews to have seen this problem before?” It also means that they’ve put little to no effort into their interview process, and by extension probably their professional evaluation and development internally are terrible. You deserve better than to work for a company that can’t be bothered to have a better interview process than fizzbuzz.

I’ve long wanted to try to sneak a language or standard library level fizzbuzz operator into a language, so that you could answer this question with a single function call.

Hey can we use this thread to kvetch about coding tests? Because so many of them, to me, seem to be very much “do you know how to use [language or regex feature] off the top of your head?”

I recently went through one for a job I really wanted (and just got! Yay!). This was in JavaScript (it’s a full-stack Node role so JS it is) and timed. I stressed the hell out about it because the first “easy”-level problem took me a bit over the time limit because fucked if I remembered JS array and string functions off the top of my head.

I mean, I knew JS had filtering and mapping functions. I just had to Google up the syntax, which when you’re supposed to solve a problem involving splitting an input string on some (intentionally poorly defined) delimiters and then performing some logic on the results in 15 minutes, well, that’s a decent chunk of your 15 minutes.

That was an online coding test though, rather than an in-person whiteboard problem. Had a couple of those for my current role, of which the first was a deadass simple “how would you write an API to take in and sanitize an input string” thing that I felt like they hated my solution for, or maybe it was a cultural divide thing where I couldn’t read their body language (or they were just cold fish, idk).

The other one, which was much more fun, was “how would you design data stores and APIs to talk to them for this relatively simple business problem, at a very high level aka no pseudocode or anything, just talk about API layers and data store structures.” I felt like that one I did well at (I’m pretty convinced it’s what got me this job) and let me actually engage my problem-solving brain rather than testing my knowledge of language or framework features.

I’ve been considering staring a separate “General Technical Interview Discussion” thread, because I suspect there are enough people here with experience and opinions that it may be interesting.

I think that’s a great idea!

I suppose it will filter out the people who are literally too incompetent to program. And they do exist. I once did some maintenance on a program which ought not to work at first sight.

DO WHILE end-off-file
process file stuff
END

It would appear that reading through any non-empty file, the program should terminate immediately. But it did not. It was a COBOL program, and the original programmer got it working by defining TRUE to be false, and FALSE to be true. So in this case, two wrongs made it right.

Apparently, you can do something similar in Go:

Ah, so this is the thread to talk about coding/programming horror stories? Because I don’t think I’ll sleep today after hearing that one.

Fortran was infamous for stuff like that. You could accidentally (or on purpose) change the values of constants. Redefining zero was always a fun one to track down.

Friend of mine discovered SQL triggers that were apparently manually added to the prod database instance with no documentation anywhere, no representation in the repo or anything, that were (shockingly) causing bugs and weird behavior. Still makes me shudder to think about.

Oh boy, don’t get me started on triggers. I’m triggered.

I mean, I haven’t encountered them myself, but they seem like a real dumb/bad/opaque way to accomplish whatever you’re trying to do.

This is the same place, incidentally, that implemented a TTL on their database by, on every call to the backend, querying every table and deleting every record created < whatever timestamp.

Those engineers, you’ll be shocked to learn, all got sacked a while back.

I had numerous problems caused by wayward triggers in a legacy database.

It’s bad enough that I rarely consider triggers when designing a system - because of their relative “obscurity”, so to speak. Of course, there are cases in which triggers are the ideal solution, but then I go out of my way to make sure they’re all listed and documented (even with mentions in application source code wherever there’s code that might be impacted by the trigger’s existence, so people know they exist and what they do).

You can say I developed PTSD - Post Trigger Stress Disorder. I’m just trying to keep that from happening to others (and to myself).

Not quite the same, but I once got a job because I knew how to make a pivot table. I was stunned this set me apart.

When I was last looking for a programming job I did a lot of research into programming tests and whether or not they are of any value. In summary: I believe programming tests are useful to weed out imposters but they don’t have much value in identifying great performers. Therefore I don’t mind a “fizzbuzz” test since it shows if you know how to program. But I won’t stand for those stupid tests where you have to do 90 minutes on some sort of environment where they all watch you work.

I had a company ask me to implement a webserver talking to a database with a simple Angular front end (this was a few years ago, so no React). At the time I thought about doing it just because I thought it might be a fun exercise. But then I decided I didn’t want to invest a couple of hours for free for this company, and I told them no.

Some companies can get away with stuff like this - Apple, Google, Amazon. But for a no-name local company to ask someone to do this? Get lost!*

        * I am also a special case since I have a security clearance and do programming and am in an area (NoVA) where demand is incredibly high, so I have the luxury of being able to turn people down without worrying about the next opportunity.

For the job I’m leaving, I did a project of putting together an API that calls an API from their business and stores the returns in a local database. That was kinda fun, and no doubt a factor in getting me the job (I went pretty above and beyond with it).

The question I like to ask is, “On an analog clock, how many times do the hour and second hands overlap in 24 hours?” It’s interesting to see how folks think through the problem. Not a coding test at all though, or really even technical.

Virtually no one gets it right initially, but virtually everyone eventually figures it out.

The very first guy I interviewed after adding this question in though, really struggled, and gave some really bad answers… The rest of the interview went well enough, and I hadn’t placed much faith in this particular question at that point. But eventually, that dude had major problems, and upon reflection his problems ended up being related to his bad approach to that question… so I ask it every time now.

In terms of basic “can you code” questions, we have one of those. It’s in there largely as a matter of habit, as it was in there back when I got hired.

I’m not sure it serves any purpose at all. It’s kind of a warmer upper, I guess. Just “write something to reverse a string”. I usually follow by asking them to then write a recursive version of the same function. I think maybe it demonstrates something in that you’re wriiting code in a totally weird, unfamiliar setting, without a computer. But really, I think it’s mainly in there as a matter of habit now, and I’ve considered replacing it with something better.