• 0

Programmers: Your favorite interview questions


Question

I haven't seen one these posts yet on this forum(if there is forgive me : )), but I figured to help out more people looking for programming work I would start a post for employers who are looking to hire new programmers what kind of questions you guys ask. I'm the technical director at a small game studio in LA, and were expanding so I also looking to see what everyone does so I can adjust accordingly.

Some of the basic questions I ask are:

What is global scope/local scope.

What is a template class

What is inheritance/polymorphism/etc.

Than some really basic logic stuff like whats a recursive function, etc etc.

Than I begin to ask a couple questions that are kind of off the wall because one thing I noticed is College graduates from big schools such as UCLA 9/10 can't figure stuff for themselves. Students are so used to stuff getting spoon fed to them, some of which is just nasty. One thing that really irritated me at one of the studios I worked at previously a couple of there senior programmers came to me and said "I don't know how to do xyz, can you help?" This normally is a pretty common thing, except when xyz happens over and over again and its something that easily be found by doing a quick google search.

I ask the interviewee if they can do something that 99% of the programmers out there can't do. They would obviously say I don't know, I would then ask them than to look it up for me on google and write out basic steps on how to get it done. Lets say I ask them how to register a custom Debug Engine in Visual Studio, first google search for "visual studio custom debug engine" which turns up http://msdn.microsof...4(v=vs.80).aspx , with a link to http://msdn.microsof...(v=vs.110).aspx. Even though the information on the latter article is actually wrong if they copied that I would be so happy. I've had guys sit there for 10 minutes struggling, and I feel that's kind of ridiculous. Every programmer in world should know how to use google :/.

Than depending on the level of the job, I would go into some more nitpicker things say in Unreal, Unity, D3D, whatever and if someone didn't know the answer I would ask them to google it and give me an explanation. I had actually had one guy who didn't graduate from a college, straight out of high school and he didn't know something I asked him, and than he immediately asked if he could go on google and look it up. I actually hired him on the spot and he ones of the best programmers I've ever had.

Anyway what kind of stuff do you guys ask?

Recommended Posts

  • 0

The trick is that the naive algorithm only works with a monospace font. The extreme case, a string composed of 'i's, will hold much more letters than normal text in a certain amount of pixels. So you have to measure the text if you want to do it correctly.

but the way he wrote the question it said nothing about text width

2. In Java, write a function which takes a string and returns a string that is the input if the input is 6 characters or less, and the first 3 characters + "..." if it's greater than 6.

that is pretty straight forward, you are only careing about the number of characters... now if you said that as fit a string of text into a row that is 250 pixels wide with the font arial, and type settings of 12pt and bold, itallic, replace any overlap with an elipsis... that would make more sense... can't be a trick question if it only says take 6 char's replace anything over 6 with the first 3 plus an elipsis...

  • Like 2
  • 0

but the way he wrote the question it said nothing about text width

2. In Java, write a function which takes a string and returns a string that is the input if the input is 6 characters or less, and the first 3 characters + "..." if it's greater than 6.

that is pretty straight forward, you are only careing about the number of characters... now if you said that as fit a string of text into a row that is 250 pixels wide with the font arial, and type settings of 12pt and bold, itallic, replace any overlap with an elipsis... that would make more sense... can't be a trick question if it only says take 6 char's replace anything over 6 with the first 3 plus an elipsis...

Well, that's partially why I mentioned that the question is poorly defined. But the main issue is that Java strings are UTF-16, NOT UCS-2. So if you have a string where the first code point is a surrogate pair, then the naive algorithm will produce an invalid string. So what you want is code points. Of course, that's not the entire story. What do you do about control characters? You probably want to interpret those ones you can, like BOM. But what about accents and other "modifiers". Those aren't entire characters, so you probably want to treat "e" and circumflex as a single character. And of course, if the reason why you doing this is to display the string in a restricted space, then the whole "6 characters" is moot since you now need to take into account font, size, weight, and any number of other rendering factors. So overall, not an easy question.

  • 0

Well, that's partially why I mentioned that the question is poorly defined. But the main issue is that Java strings are UTF-16, NOT UCS-2. So if you have a string where the first code point is a surrogate pair, then the naive algorithm will produce an invalid string. So what you want is code points. Of course, that's not the entire story. What do you do about control characters? You probably want to interpret those ones you can, like BOM. But what about accents and other "modifiers". Those aren't entire characters, so you probably want to treat "e" and circumflex as a single character. And of course, if the reason why you doing this is to display the string in a restricted space, then the whole "6 characters" is moot since you now need to take into account font, size, weight, and any number of other rendering factors. So overall, not an easy question.

I don't know about all accents, but in UTF-16 the circumflex and other common accents are not separated from the character. (IIRC, windows-1257 does that, which is useful to remove accents from a string by converting it back into ASCII)

But your question was worded in a way that makes "s.length <= 6 ? s : s.substring(0,3)" an acceptable answer.

  • 0
Well, that's partially why I mentioned that the question is poorly defined.
Then define properly the request. "Character" in Java means "Unicode scalar value" {\u0000 ? \u10FFFF}.
And of course, if the reason why you doing (?)
It is irrelevant because it was not stated in the request.
  • 0

I have a really hard time believing any "programmer" could be eliminated by the fizzbuzz question (I wish I had easy questions like that for my interviews :/)

Personally I think most "interviews" for developers are ridiculous and are usually aimed at making the person fail (only tool you have are pencil and paper and the questions are most of the time extremely obscure and could be answered with more time/better tools)

I know most people I work with that are "good" at interviews are usually just that, most of their code usually look like crap.

  • 0

That's the whole pitfall of FizzBuzz (unless you do duplicate checks, which is usually not wanted)

Could you give the solution? Or is the solution language specific, like Python assigment:

A, B = B, A 

But still, internally I'm sure a temporary variable(s!) is being used.

EDIT: Forgot to add my solution.

void FizzBuzz()
{
	for (int num = 1; num  &lt; 101; num ++)
	{
		bool multiple = false;
		if (num % 3 == 0)
		{
			cout &lt;&lt; "Fizz";
			multiple = true;
		}
		if (num % 5 == 0)
		{
			cout &lt;&lt; "Buzz";
			multiple = true;
		}
		if (!multiple)
			cout &lt;&lt; num;
		cout &lt;&lt; endl;
	}
}
[/CODE]

I'm still not sure if it's better to declare a variable outside of the loop, but I'm fairly sure it will be optimized by the compiler.
And my solution is fairly readable (I hope).

Why not use an else clause rather than a variable?
[code]void FizzBuzz()
{
        for (int num = 1; num  &lt; 101; num ++)
        {
                if (num % 3 == 0)
                {
                        cout &lt;&lt; "Fizz";
                }
                else if (num % 5 == 0)
                {
                        cout &lt;&lt; "Buzz";
                }
                else
                        cout &lt;&lt; num;
                cout &lt;&lt; endl;
        }
}

  • 0

Why not use an else clause rather than a variable?

Because in the case of %3 && %5 you need to print 'FizzBuzz'. Now you don't and have failed the assignment (into it's pitfall).

That's why I have a boolean variable that keeps track of whether it printed "Fizz" OR "Buzz". I thought about doing

it differently, something with scopes but that wouldn't do much and my solution is fairly readable and simple.

  • 0

Why not use an else clause rather than a variable?

void FizzBuzz()
{
        for (int num = 1; num  &lt; 101; num ++)
        {
                if (num % 3 == 0)
                {
                        cout &lt;&lt; "Fizz";
                }
                else if (num % 5 == 0)
                {
                        cout &lt;&lt; "Buzz";
                }
                else
                        cout &lt;&lt; num;
                cout &lt;&lt; endl;
        }
}

You failed!

You're missing the FizzBuzz state (if dividable by both 3 and 5 aka divisible by 15)

  • 0

I've been asked that question. As soon as you give the solution using modulus, they ask you to do it again without using modulus/multiplication/division.

I assumed by that you meant no arithmetic operations (including bitwise) whatsoever and was like hmm that's impossible. But, I see it was only the particular types.

 

EDIT: well other than just comparisons over and over...  :laugh:

  • 0

 

  • Given two integer variables, A and B, how could you swap their values without using a third variable? (This is my favourite. It wasn't actually given to me, but to my housemate at the time. He didn't get it, but the interviewer gave it to him to do on the train home, he figured it out on the train and emailed the answer to the interviewer, subsequently got the job :p)

I think this is a poor question because the only solution is not really an solution since it contains defects that break the intended purpose. Clever tricks with potentially subtle bugs aren't really clever tricks at all. Personally, I would have just given an inline asm solution that only used registers and pointed out that the only memory accesses would be the fetch/storeback of A&B and that no temporary exists in memory. It's not clever and the compiler will do it automatically anyway, but it works in all cases.

 

EDIT: There's also an XOR solution for this, but it has caveats in practice also.

  • 0

I rely on their ability to solve logical problems using their own made up syntax. I've only had to hire once though so my experience in it is limited. My train of thought was that I prefer that they can solve complex problems instead of code complex solutions.

 

FizzBuzz is great and all, but I prefer someone who can learn it quickly as opposed to someone that can (re)code it efficiently; let's be honest, most of the people who pass a fizzbuzz test have already done or practiced a fizzbuzz test. I have (and for merits of ability it's in my interest to inform you all I passed it, but of course).

 

 

In the end it worked out great. They were a stronger programmer than I am, which isn't that hard to do lol.

  • Like 2
  • 0

Hello,

I actually read you guys talk about FizzBuzz and I think Im missing something:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fizzbuzz
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i=1;i<101;i++)
            {
                if   ((i % 3 == 0) && (i %5==0))
                {
                    Console.WriteLine("FizzBuzz");
                }
                else if (i % 5 == 0)
                {
                    Console.WriteLine("Buzz");
                }
                else if (i%3==0)
                {
                    Console.WriteLine("Fizz");
                }
                else
                {
                    Console.WriteLine(i);
                }
            }
            Console.ReadLine();
        }
    }
}

Something wrong with the code? :)
  • 0

Hello,

I actually read you guys talk about FizzBuzz and I think Im missing something:

 

Something wrong with the code? :)

 

 

Your code should work... but you might want to think about efficiency. If the number is divisible by 3, but not 5, you end up checking if the number is divisible by 3 twice and 5 twice.

 

But efficiency can be misleading. Should we optimize for (code) space efficiency, memory efficiency, or time efficiency... and how much longer should we assume a multiply/divide/modulus takes than an add?

  • 0

Your code should work... but you might want to think about efficiency. If the number is divisible by 3, but not 5, you end up checking if the number is divisible by 3 twice and 5 twice.

 

But efficiency can be misleading. Should we optimize for (code) space efficiency, memory efficiency, or time efficiency... and how much longer should we assume a multiply/divide/modulus takes than an add?

No point in wasting time or effort on simple optimizations that the compiler is going to do for you anyway: it just obfuscates the high level code for no benefits in practice. Same with throwing away assignments to temporary variables.

  • 0

No point in wasting time or effort on simple optimizations that the compiler is going to do for you anyway: it just obfuscates the high level code for no benefits in practice. Same with throwing away assignments to temporary variables.

 

I absolutely agree. However, your interviewer is going to have some questions for you after you finish writing the code. It's good to have some answers about efficiency, and other possible ways to write it.

It's a shame this topic got so hopeless devoted to beating the dead FizzBuzz horse. There are much more interesting questions that are more likely to be asked. Other than Hulu, who asked me to code FizzBuzz, every other interview I have been on have asked questions about linked lists... and sometimes about doubly linked lists.

  • 0

I absolutely agree. However, your interviewer is going to have some questions for you after you finish writing the code. It's good to have some answers about efficiency, and other possible ways to write it.

True that, any interviewer worth their salt will try to explore the problem and see your logical processes. The thing is, I see suggestions to do those sort of thing in real code in spots where it is obviously not any sort of bottleneck all of the time. In practice, I think it is focusing on the wrong thing in real world optimization.

 

It's a shame this topic got so hopeless devoted to beating the dead FizzBuzz horse. There are much more interesting questions that are more likely to be asked. Other than Hulu, who asked me to code FizzBuzz, every other interview I have been on have asked questions about linked lists... and sometimes about doubly linked lists.

I've heard google asks some difficult questions (none of that FizzBuzz). Another question I've heard is the algorithm for palindromes, and then to step it up to more difficulty, finding the sub palindromes (including shifted palindromes, e.g. abbattttttttttt, where 'abba' and 'bb' are matches).

  • 0

True that, any interviewer worth their salt will try to explore the problem and see your logical processes. The thing is, I see suggestions to do those sort of thing in real code in spots where it is obviously not any sort of bottleneck all of the time. In practice, I think it is focusing on the wrong thing in real world optimization.

 

I've heard google asks some difficult questions (none of that FizzBuzz). Another question I've heard is the algorithm for palindromes, and then to step it up to more difficulty, finding the sub palindromes (including shifted palindromes, e.g. abbattttttttttt, where 'abba' and 'bb' are matches).

 

I've had all of those logical questions (fizzbuzz, palindromes, you name it) on tests and exams for Java, in my 1st year of college (1st semester, really); it really pushes the logical thinking forward so when a student starts learning higher maths, physics and programming it can use the rational thinking to think out of the box.

 

by the way: i'm not a programmer :)

 

the problem solving aspect is one of the most valuable things a programmer must have (not only just the programmer, but since this is the topic...), not to mention code knowledge and the ability to learn new stuff. I've had questionable interviews made by psychologists that didn't know jack about the job i was being interviewed (and therefor they used questions that anybody could find on the interwebs, not really doing a good job filtering the interviewer really) or being asked incredible dumb and trick questions that made me want to question why should i want to join an enterprise that can't even do a proper interview; when i answered all those questions i realized that all they wanted is someone that was good but for cheap. :/

 

so, answering OP (this thread is kind of oldie...2012, eh?): my favorite question i ever had in a interview was:

- HR woman: "well lets see... i think for starting the paycheck will be 1400?..."

- Praetor: /does an incredible stunned face since i don't even get 1000? (tough days we are getting in my country)... 1400? for starting is a very welcome jump!

- HR woman: "oh... you seem really upset; i think we can push to 1500? + bonus, is that OK for you?"

- Praetor: / eyes pupils change to euro signs. :woot:

  • Like 2
  • 0

I've had all of those logical questions (fizzbuzz, palindromes, you name it) on tests and exams for Java, in my 1st year of college (1st semester, really); it really pushes the logical thinking forward so when a student starts learning higher maths, physics and programming it can use the rational thinking to think out of the box.

 

by the way: i'm not a programmer :)

 

the problem solving aspect is one of the most valuable things a programmer must have (not only just the programmer, but since this is the topic...), not to mention code knowledge and the ability to learn new stuff. I've had questionable interviews made by psychologists that didn't know jack about the job i was being interviewed (and therefor they used questions that anybody could find on the interwebs, not really doing a good job filtering the interviewer really) or being asked incredible dumb and trick questions that made me want to question why should i want to join an enterprise that can't even do a proper interview; when i answered all those questions i realized that all they wanted is someone that was good but for cheap. :/

 

so, answering OP (this thread is kind of oldie...2012, eh?): my favorite question i ever had in a interview was:

- HR woman: "well lets see... i think for starting the paycheck will be 1400?..."

- Praetor: /does an incredible stunned face since i don't even get 1000? (tough days we are getting in my country)... 1400? for starting is a very welcome jump!

- HR woman: "oh... you seem really upset; i think we can push to 1500? + bonus, is that OK for you?"

- Praetor: / eyes pupils change to euro signs. :woot:

I think you are absolutely right: many of these are just simple 1st year assignment type things. And, really, they are just used to weed out applicants who can't even do that much. At the same time when you start to step up the difficult and have them work through successively more difficult versions of a similar problem, you get a feel for how the applicant approaches problem solving. That's how I'd conduct an interview myself. For example, asking the interviewee how they'd handle arbitrary sized swaps in the case of the integer swapping, asking what the potential problems are; or in the case of the palindromes asking for a better complexity solution than what is probably going to be offered. Just seeing if they can reason through things like that.

 

You know, now that you pointed out the thread is from 2012, I'm not even sure HOW I managed to get to it. I could have sworn I clicked on the updated threads or spy and saw it there. I rather do like your answers though. I think they fit the bill better for favorites.

  • 0

Guys, this thread is from 2012.

That's my fault. I didn't notice that when I initially posted. But like I said before, I'm not even sure how I ended up on the thread to post since I only go to threads though the spy or thread lists.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Windows 11 gets useful new File Explorer features in the latest build by Taras Buria Friday Windows 11 preview builds are finally here. After skipping one week, Microsoft is back to releasing preview builds for Windows Insiders to try. This time, Insiders in the Experimental Channel can download build 26300.8687. Its changelog does not contain anything major, but there is still useful new stuff, such as some new conveniences for File Explorer, Windows Update improvements, better Windows Search, a new search provider for the built-in GIF library, and more. Here is the changelog: [Windows Update] As announced in the Windows Update announcement blog, we are now bringing a new unified update experience to reduce the number of reboots you see per month. We are starting by coordinating driver, .NET, and firmware updates to align with the monthly quality update, reducing the update experience to a single monthly restart. See the blog for more information. [File Explorer] Middle-click to open a folder in a new tab is now supported in the Address Bar and the Home page for a more consistent and efficient tabbed navigation experience across File Explorer. Improved screen reader announcements for conflict resolution dialog ("Which files do you want to keep?") when moving/copying files. Made some more improvements to how File Explorer responds to increased text scaling. [Search] Finding apps is more forgiving. Search is better at handling typos, dropped letters, extra letters, and partial words for apps. Queries like “utlook” can still find Outlook. Settings results are improving. We’ve made ranking improvements to help more relevant settings appear higher in results. [Taskbar] Improved reliability of loading the system tray area of the taskbar. Fixed an issue where tooltips might unexpectedly appear on top of the Start menu icon in the taskbar when using the taskbar in an alternate position. Also fixed a few other visual polish issues when using the taskbar with small icons. [Windows setup] The digital safety of users and supporting families is central to how we think about the Windows experience. We're improving information on parental controls and their availability during Windows setup, so families can more easily understand available protections and make informed choices from the very beginning. [Input] Update: The emoji panel (Windows key + period (.)) now uses GIPHY as the GIF provider, delivering a smoother GIF browsing and sharing experience following the deprecation of Tenor. Fixed an issue that was causing the mouse cursor to potentially move in the wrong direction in recent Insider builds on secondary monitors when set to portrait mode. [Remote Recovery Management] Adding a recovery remote management plug-in for extending WinRE management capabilities for MDM providers [Audio] Fixed an issue resulting in audio not working for some Insiders after the latest flights. [Settings] Fixed an issue impacting the reliability of Settings > Apps > Installed Apps after the latest flights. [General Reliability] If you were experiencing freezes in the previous flight when interacting with search, Notepad, or certain other scenarios, that should be resolved now. [Other] When using dark mode, if you open "Run new task" from Task Manager, it will now show in dark mode too. As usual, changes above are rolling out gradually. You can find the release notes here in the official documentation.
    • Im in Ohio, and my VPN endpoint is in Boston. If that helps, it does happen both on and off the VPN. and again only in Edge.
    • It is such a shame. I used to really respect Neowin's articles.
    • So.... slower fixes and slower security updates are preferred? I mean, there is no goldilocks zone here until it can literally update without ever needing a restart, and even then I'm sure someone would complain.
  • Recent Achievements

    • One Month Later
      Clizby earned a badge
      One Month Later
    • One Month Later
      Timaximus earned a badge
      One Month Later
    • Week One Done
      Timaximus earned a badge
      Week One Done
    • Rookie
      FBSPL went up a rank
      Rookie
    • First Post
      davidbazooked earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      490
    2. 2
      PsYcHoKiLLa
      168
    3. 3
      +Edouard
      163
    4. 4
      Steven P.
      85
    5. 5
      ATLien_0
      76
  • Tell a friend

    Love Neowin? Tell a friend!