• 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

    • Samsung messages is still alive and well. They reversed that and decided to our more effort into it.
    • I think every American should have a course in a 'dry sense of humour' at school; and perhaps 'using sarcasm in jest' oh, and also 'the use or irony in humour'.
    • What they really need to do is automatically spell "loses" and "lose" correctly since nobody seems to know how to anymore. Then they blame spellcheck/autocomplete and don't realize autocomplete is just filling in the word for them automatically so it was misspelled in the first place.
    • If someone chooses to continue using SB and therefore goes through the manual intervention in the thread, afterwards the BSOD problem is gone. Whether they then re-enable the task doesn't matter, they're done, though on such machines it might pay to keep it disabled in case the next update (if there is a next) causes the same problem. OTOH, if someone disables SB in the BIOS, the problem is also gone. Incidentally, I noticed that this task exists even on machines that don't support SB. It's just installed across the board...and runs. Doing what on such machines is a little hazy.
    • qBittorrent 5.2.2 by Razvan Serea The qBittorrent project aims to provide a Free Software alternative to µtorrent. qBittorrent is an advanced and multi-platform BitTorrent client with a nice user interface as well as a Web UI for remote control and an integrated search engine. qBittorrent aims to meet the needs of most users while using as little CPU and memory as possible. qBittorrent is a truly Open Source project, and as such, anyone can and should contribute to it. qBittorrent features: Polished µTorrent-like User Interface Well-integrated and extensible Search Engine Simultaneous search in most famous BitTorrent search sites Per-category-specific search requests (e.g. Books, Music, Movies) All Bittorrent extensions DHT, Peer Exchange, Full encryption, Magnet/BitComet URIs, ... Remote control through a Web user interface Nearly identical to the regular UI, all in Ajax Advanced control over trackers, peers and torrents Torrents queueing and prioritizing Torrent content selection and prioritizing UPnP / NAT-PMP port forwarding support Available in ~25 languages (Unicode support) Torrent creation tool Advanced RSS support with download filters (inc. regex) Bandwidth scheduler IP Filtering (eMule and PeerGuardian compatible) IPv6 compliant Available on most platforms: Linux, Mac OS X, Windows, OS/2, FreeBSD qBittorrent 5.2.2 changelog: FEATURE: Use D-Bus to show file in file managers (Chocobo1) #24340 BUGFIX: Fix friendlyUnitCompact precision calculation (vafada) #24323 BUGFIX: Remove all top-level folders (glassez) #24333 BUGFIX: Use proper API for checking exit status (Chocobo1) #24349 BUGFIX: Delete stale lockfile when hostname mismatch (TurboTheTurtle, glassez) #24363 BUGFIX: Fix wrong removal procedure of watched folder paths (Chocobo1) #24413 BUGFIX: Don't reannounce before interface changes are applied (glassez) #24447 BUGFIX: Use Latin script for Bosnian locale name (Andy Ye) #24342 WEBUI: Fix performance of global checkbox toggling (tehcneko) #24316 WEBUI: Fix Safari transfer list header misalignment (Piccirello) #24377 WEBUI: Fix error when submitting magnet before metadata loads (Piccirello) #24378 WEBUI: Use correct row id when updating Rss Downloader feed selection (Chocobo1) #24402 WEBUI: Use SameSite=Lax for session cookie to fix cross-site login (Piccirello) #24422 WEBUI: Bring back properties panel expand/collapse button (vafada) #24430 WEBAPI: Only use X-Forwarded-Host header when reverse proxy support is enabled (Chocobo1) #24457 RSSS: Fix "RSS Smart Episode Filter" RegEx (nathanon-akk, glassez) #24398 RSS: Fix previously matched episode format (glassez) #24452 WINDOWS: Fix Python fallback search path (TurboTheTurtle) #24325 WINDOWS: NSIS: Allow to install x64 binary on ARM64 (Chocobo1) #24358 Download: qBittorrent 5.2.2 | 41.1 MB (Open Source) Download: qBittorrent 64-bit installer (qt6) | 43.6 MB Links: qBittorrent Home page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Month Later
      Twozo Technologies earned a badge
      One Month Later
    • Week One Done
      Twozo Technologies earned a badge
      Week One Done
    • One Year In
      Twozo Technologies earned a badge
      One Year In
    • Veteran
      branfont went up a rank
      Veteran
    • Reacting Well
      Almohandis earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      497
    2. 2
      +Edouard
      183
    3. 3
      PsYcHoKiLLa
      126
    4. 4
      Steven P.
      85
    5. 5
      neufuse
      71
  • Tell a friend

    Love Neowin? Tell a friend!