Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 19, 2011, 07:24 PM   #1
chrono1081
macrumors 604
 
chrono1081's Avatar
 
Join Date: Jan 2008
Location: Isla Nublar
Does anyone have any good recommendations for obtaining programming test questions?

Hi guys,

I've been working on getting my first programming job and I tried looking up programming test questions for entry level programming positions and they are either way too easy to be real (like write a program that counts from 10 - 1, or write a program to count words in a file), or way too hard (for entry level) such as questions relating to programming solutions for encryption programs relating to cloud storage and things like that that a beginner I would assume not be expected to know.

Does anyone have any real world examples of what kind of questions are asked on programming tests? Does anyone here interview programmers and could throw me a few questions by chance? Any help would be greatly appreciated

EDIT: I'm looking at questions for entry level C++ coding jobs or entry level iOS development jobs.
__________________
Mac Pro (2010): 3.33Ghz Intel Xeon (6 core) - 24 GB RAM - NVidia Quadro k5000
Macbook Air (2010): 2.13 Ghz Intel Core 2 Duo - 4GB RAM
chrono1081 is offline   0 Reply With Quote
Old Aug 19, 2011, 08:42 PM   #2
JoshDC
macrumors regular
 
Join Date: Apr 2009
In my quite limited experience for university and industrial placements, questions often are quite easy. This is because they're more interested in how you get to the answer.

One that I was given was "Sum all numbers between two arbitrary values". If you don't put much thought into you might be tempted by:

Code:
for (int i = start; i <= end; i++) {
    total += i;
}
Which is complexity n, and not really that great. Doing a bit of research (or remembering some math), you can use a summation formula, such as:

Code:
total = (start + end)*(end - start + 1) / 2
Which is constant complexity, and much better in the majority of situations.

Point is there'll usually be a number of different answers: some better than others. It's your job to walk through your thoughts, why you dismissed certain options, and why you chose the solution you did.

Again, with the word count question there are a number of different options (good and bad) to the one you claim is easy! It's probably worth mentioning when'd you'd use libraries/frameworks in production code. While it's clearly not the approach the question wants you to take, Cocoa has a method to enumerate words that will almost certainly have a better concept of what a "word" is than what you can come up with in an interview/short test.

A couple of other questions I can remember are:

How do you switch the value of two variables without an intermediary variable? (x,y = y,x in Python, but that's cheating!)
How do you efficiently store a sparse 2D list of values?

Hope this helps.
JoshDC is offline   0 Reply With Quote
Old Aug 19, 2011, 09:45 PM   #3
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
The most recent interview I was conducting was for a DBA, and all of my questions were high-level, not asking to write queries, etc.

The most recent interview I was subjected to was not entry level, but the questions weren't all incredibly involved. One round was designing the data model for an app. Two were get-to-know-you (be able to answer what your biggest flaw is, how you'd deal with a hostile co-worker, etc.), one round was Java-specific because it's a Java shop (write a dice game implementation on the whiteboard, what does this code do, set vs. List, hashing, etc.), one round was SQL... joins, subqueries, aggregates, etc. All of this was about 5 hours one afternoon after a 1 hr phone interview with a smattering of all of that.

If you're going entry-level I don't know how technical they'll get. It depends on the interviewer. Write some code on paper. Not perfect, but good enough. Logically sound if not syntactically correct. How do you handle scarce resources like file handles? If you use the XOR trick for an in-place swap be sure to check for pointer equivalence or you'll wipe your value. Hell, you could just check for equivalence of the values.

Be ready to solve a problem you've never thought about before. Get the rules to some games and write pseudo code to solve them. Know data structures. What's a map/dictionary? What's a linked list? What's a binary tree, what's the cost to rebalance it? When is the right time to use these?

Know things about your "target" language. What's a pointer? What's pass by value? A pointer by value? By reference? By const reference? What's good and bad about these? Know constructors and destructors. Know exception handling. Know inheritance. If you don't know one of these and can't figure it out in time, be honest. I'd rather someone admit that than guess wrong.

They're going to want to see how you work and how you'll fit in as much as they want to see what you know. Be yourself. If you're fake, ingenuine, etc they'll figure it out eventually.

Good luck.

-Lee
lee1210 is offline   0 Reply With Quote
Old Aug 19, 2011, 09:49 PM   #4
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Try the practice stuff at http://codility.com/

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Aug 20, 2011, 01:45 AM   #5
chrono1081
Thread Starter
macrumors 604
 
chrono1081's Avatar
 
Join Date: Jan 2008
Location: Isla Nublar
Quote:
Originally Posted by JoshDC View Post
In my quite limited experience for university and industrial placements, questions often are quite easy. This is because they're more interested in how you get to the answer.

One that I was given was "Sum all numbers between two arbitrary values". If you don't put much thought into you might be tempted by:

Code:
for (int i = start; i <= end; i++) {
    total += i;
}
Which is complexity n, and not really that great. Doing a bit of research (or remembering some math), you can use a summation formula, such as:

Code:
total = (start + end)*(end - start + 1) / 2
Which is constant complexity, and much better in the majority of situations.

Point is there'll usually be a number of different answers: some better than others. It's your job to walk through your thoughts, why you dismissed certain options, and why you chose the solution you did.

Again, with the word count question there are a number of different options (good and bad) to the one you claim is easy! It's probably worth mentioning when'd you'd use libraries/frameworks in production code. While it's clearly not the approach the question wants you to take, Cocoa has a method to enumerate words that will almost certainly have a better concept of what a "word" is than what you can come up with in an interview/short test.

A couple of other questions I can remember are:

How do you switch the value of two variables without an intermediary variable? (x,y = y,x in Python, but that's cheating!)
How do you efficiently store a sparse 2D list of values?

Hope this helps.
Wow thanks so much for that! I never thought about optimizing a simple loop like that but it makes perfect sense. I could even take that division out and multiply it by 0.5 (something I do frequently in graphics code).

Sadly I cannot answer the switching variables without an intermediate question I'd assume maybe using bitwise operators but again, without researching I honestly can't answer that :/

Even worse is I don't know what a sparse 2D list of values is I'm assuming based of other code I've ran across (and feel free to correct me since I know I'm about to be wrong) that a sparse list would be something like numbers with large differences in values, like 1, 450, 45632, 300,000 etc. To store it efficiently I'd assume you'd use hash tables but again, I really have no clue on that one without looking something up.

I'm starting to not feel so good about myself : / (No matter I'll learn and get better).


Quote:
Originally Posted by lee1210 View Post
The most recent interview I was conducting was for a DBA, and all of my questions were high-level, not asking to write queries, etc.

The most recent interview I was subjected to was not entry level, but the questions weren't all incredibly involved. One round was designing the data model for an app. Two were get-to-know-you (be able to answer what your biggest flaw is, how you'd deal with a hostile co-worker, etc.), one round was Java-specific because it's a Java shop (write a dice game implementation on the whiteboard, what does this code do, set vs. List, hashing, etc.), one round was SQL... joins, subqueries, aggregates, etc. All of this was about 5 hours one afternoon after a 1 hr phone interview with a smattering of all of that.

If you're going entry-level I don't know how technical they'll get. It depends on the interviewer. Write some code on paper. Not perfect, but good enough. Logically sound if not syntactically correct. How do you handle scarce resources like file handles? If you use the XOR trick for an in-place swap be sure to check for pointer equivalence or you'll wipe your value. Hell, you could just check for equivalence of the values.

Be ready to solve a problem you've never thought about before. Get the rules to some games and write pseudo code to solve them. Know data structures. What's a map/dictionary? What's a linked list? What's a binary tree, what's the cost to rebalance it? When is the right time to use these?

Know things about your "target" language. What's a pointer? What's pass by value? A pointer by value? By reference? By const reference? What's good and bad about these? Know constructors and destructors. Know exception handling. Know inheritance. If you don't know one of these and can't figure it out in time, be honest. I'd rather someone admit that than guess wrong.

They're going to want to see how you work and how you'll fit in as much as they want to see what you know. Be yourself. If you're fake, ingenuine, etc they'll figure it out eventually.

Good luck.

-Lee
Thank you so much for the advice! But again, ouch. Although I could write many game pseudocode implementations (I focus on games in my programming), I could not explain what checking for equivalence in values means without googling it. I haven't ran across that in any of the roughly 8 C++ books I've gone through over the years. (I started learning it in 1998 I believe). I am also very unfamiliar with bitwise operators. I've seen them, but no books (the ones I have anyway) go into detail about how or where to use them. The closest I've gotten was "They're used for flags". Again, something else I will definitely brush up on. (I'm making quite a long list!)

As for data structures, I'm familiar with some of them, not all. I don't know what a map is but I do know dictionaries, linked lists, binary trees, and a few others are. I do not know the cost to balance one. I hope that I just skimmed over that in one of my data structures books and its in fact in there somewhere.

As for pointer, references, const references, constructors, destructors, etc, I am good with all of these, same with inheritance. I'm sure there is plenty to learn but I use these on a regular basis. One thing that caught my eye was the bad about const references. I'm sure I could think of a reason eventually but right off the top of my head I cannot.

Again, thanks so much for the advice!


Quote:
Originally Posted by balamw View Post
Try the practice stuff at http://codility.com/

B
This site is awesome! Thanks so much! Sadly I took the practice test and failed. Well, not really failed since I spent 10 min on it and had to leave but I didn't fully understand the question on it which is pretty bad I'm going to try it again later when I have more time and hopefully the answer will pop in there.

Thanks so much for the advice guys, I thought I was ready for a programming job but it doesn't seem so Even though I can generally get anything I've tried running smoothly I've been having trouble answering some of the basics thrown at me here.

No matter though, I will simply keep practicing. I practice every day but not as much as I need to, school really does get in my way. (100 hours of school work a week that isn't programming doesn't help things). Luckily I graduate in October and will have plenty of time then to not only finish an iOS game I've been working on for 3 months but also time to sit down and really analyze my programming skills, what I know and don't know and focus on what I need to.

Thank you guys again for the suggestions. It really helps me to know what to study and how to get my skills in order to get my first programming job. If anyone has any other suggestions please feel free to comment
__________________
Mac Pro (2010): 3.33Ghz Intel Xeon (6 core) - 24 GB RAM - NVidia Quadro k5000
Macbook Air (2010): 2.13 Ghz Intel Core 2 Duo - 4GB RAM
chrono1081 is offline   0 Reply With Quote
Old Aug 20, 2011, 06:36 AM   #6
JoshDC
macrumors regular
 
Join Date: Apr 2009
Quote:
Originally Posted by chrono1081 View Post
Even worse is I don't know what a sparse 2D list of values is I'm assuming based of other code I've ran across (and feel free to correct me since I know I'm about to be wrong) that a sparse list would be something like numbers with large differences in values, like 1, 450, 45632, 300,000 etc. To store it efficiently I'd assume you'd use hash tables but again, I really have no clue on that one without looking something up.
You're right about what it is. I think that's my fault for not explaining it well. The solution I was given was a linked list of linked lists, but in some ways I think the hash table is better!

Quote:
Originally Posted by chrono1081 View Post
Sadly I cannot answer the switching variables without an intermediate question I'd assume maybe using bitwise operators but again, without researching I honestly can't answer that :/
You're on the right track with bitwise operators. It may help to simplify it to switching two integer variables, in which case you don't use bitwise operators.

Don't feel bad about not getting the questions straight away. They were interview questions and designed to see how you approach a problem, not if you know a load of obscure techniques. I don't think they would have looked that favourably on someone who just gave a load of model answers without justification.
JoshDC is offline   0 Reply With Quote
Old Aug 20, 2011, 07:39 AM   #7
pilotError
macrumors 68020
 
pilotError's Avatar
 
Join Date: Apr 2006
Location: Long Island
Quote:
Originally Posted by chrono1081 View Post
I am also very unfamiliar with bitwise operators. I've seen them, but no books (the ones I have anyway) go into detail about how or where to use them. The closest I've gotten was "They're used for flags". Again, something else I will definitely brush up on. (I'm making quite a long list!)
Your starting to realize that you can't possibly know everything. It's a perfectly acceptable answer to say you don't know something.

I hate interviewing, as it's mostly ********. Seriously, I would probably walk out on being asked to write a little simulation game. It has no basis in reality for most positions (I know they like to see how people problem solve), but most jobs don't require this level of thinking, and they certainly don't require you to do this on the spot.

As far as bitwise operators, they aren't used all that much outside of communications and something that has way too many flags.

A quick example: instead of having eight separate boolean values to describe a bunch of yes/no type descriptions, you can have one byte (8 bits that can have a 1 or 0) to describe the same thing with much less storage. When your sending stuff out on the net in large quantities (ie. stock quotes - 320k quotes / second), 8 separate bytes to describe something, compared to 1 byte does make a noticeable difference.

The other place you see them is when calling routines like window setup, where you define what visual elements you want to be shown (ie. border, etc.). But like others have said, you can convert to to an integer to deal with it.

There's also some cool things you can do with fast division/multiplication using the shift operators << and >>, but honestly, you don't see it all that much. In the old days when your CPU was slow and you had limited memory, you sought out these types of optimizations, but aside from embedded applications, there isn't a real need for it.

You out of college, stick with the type of questions you've been looking at and don't worry about what you don't know.

One question I was asked recently was to convert a number into Roman Numerals. I did mine the way you probably would when you google it, but the guy showed me a faster way. Good academic exercise, but your chances of pulling the most optimal answer out of the air are pretty slim.

Like Lee said, some of it is technical, a lot of it is personality and would you fit in here type of things.
pilotError is offline   0 Reply With Quote
Old Aug 20, 2011, 07:45 AM   #8
mydogisbox
macrumors member
 
Join Date: Jan 2011
This is the page I used to prepare for my recent interviews. For an entry level job if you can answer 80% of them you're probably quite well prepared.

http://www.decompile.com/interview/C..._Questions.htm

Make sure you don't neglect the generic interview questions though. (Why do you want this job? Why do you think you're a good fit for this company? etc)
mydogisbox is offline   0 Reply With Quote
Old Aug 20, 2011, 08:07 AM   #9
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Another good site for general programming practice is http://www.projecteuler.net/

When ever I look at a new language I try and do some of the exercises which helps enormously when trying to remember a new language.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old Aug 20, 2011, 10:02 AM   #10
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
The XOR in-place swap is a "classic" trick. It uses this property of exclusive-or:
(A XOR B) XOR A => B
This is because A XOR A always yields all 0 bits, and 0 XOR A always yields A.

Code:
void inPlaceSwap(int *a, int *b) {
  if(a == b) return;
  if(a == NULL || b == NULL) return;
  *a = *a ^ *b; //a' now contains a XOR b
  *b = *a ^ *b; //b' now contains a
  *a = *a ^ *b; //a' now contains b
}
My statement about comparing the values would be doing *a == *b instead of a == b. The reason it's critical to at least check for pointer equivalence is if you called this:
inPlaceSwap(&x,&x);
Then you'll lose your value in x, because x ^ x will always yield 0.

As for a map, a dictionary is the same as map. In perl it's just called a hash. It's all the same thing, a map of keys to values.

A balanced binary tree can decay to a linked list, pushing the log(n) complexity of locating an element to n. Rebalancing can put things "back in line".
http://en.wikipedia.org/wiki/Tree_rotation
This may be academic minutiae, but some interviewers are dicks.

If you can't think of anything bad about something, that's a fine answer. But you should be able to say when passing a const ref is inappropriate (i.e. when you need to change it).

If you get your iOS game in the app store, definitely mention that.

You still have a number of months to prepare, and when you do they're still going to catch you off guard. Be confident in what you do know and frank about what you don't.

-Lee
lee1210 is offline   0 Reply With Quote
Old Aug 20, 2011, 12:08 PM   #11
itickings
macrumors 6502a
 
itickings's Avatar
 
Join Date: Apr 2007
Quote:
Originally Posted by chrono1081 View Post
Wow thanks so much for that! I never thought about optimizing a simple loop like that but it makes perfect sense. I could even take that division out and multiply it by 0.5 (something I do frequently in graphics code).
One other thing to keep in mind is the difference between floating-point numbers and integers.

Dividing by the integer 2 is not necessarily equal to multiplying by the floating-point number 0.5. The two can differ both in performance and in the actual result depending on the context.
__________________
Rawr!
itickings is offline   0 Reply With Quote
Old Aug 20, 2011, 01:33 PM   #12
mrichmon
macrumors 6502a
 
Join Date: Jun 2003
Quote:
Originally Posted by itickings View Post
One other thing to keep in mind is the difference between floating-point numbers and integers.

Dividing by the integer 2 is not necessarily equal to multiplying by the floating-point number 0.5. The two can differ both in performance and in the actual result depending on the context.
Additionally, a floating point operation in the CPU is generally more expensive than an integer operation.

The divide by 2 can be removed by replacing it with a shift by one bit.
mrichmon is offline   0 Reply With Quote
Old Aug 20, 2011, 01:40 PM   #13
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
Quote:
Originally Posted by mrichmon View Post
Additionally, a floating point operation in the CPU is generally more expensive than an integer operation.

The divide by 2 can be removed by replacing it with a shift by one bit.
As long as the left operand is positive and you don't mind the obfuscation. If you've found the bottleneck in your code to be an integer divide by 2 (that the compiler probably already optimized), you're in dire straits.

-Lee
lee1210 is offline   0 Reply With Quote
Old Aug 20, 2011, 02:54 PM   #14
itickings
macrumors 6502a
 
itickings's Avatar
 
Join Date: Apr 2007
Quote:
Originally Posted by mrichmon View Post
Additionally, a floating point operation in the CPU is generally more expensive than an integer operation.
Yeah, I think that's pretty much covered by the "differ in performance" you quoted.
__________________
Rawr!
itickings is offline   0 Reply With Quote
Old Aug 23, 2011, 05:24 AM   #15
chrono1081
Thread Starter
macrumors 604
 
chrono1081's Avatar
 
Join Date: Jan 2008
Location: Isla Nublar
Thank you guys again for all of the tips and advice!

I ended up landing an interview for a job. I'm obviously nervous, not about the questions since I'm very good at interview questions (I used to interview people myself at many places) but of the test!

I know I can figure out anything thrown at me unless its something way out there but it'll be timed so I'm nervous!

Wish me luck, and thanks again for all your help Mac Rumors!
__________________
Mac Pro (2010): 3.33Ghz Intel Xeon (6 core) - 24 GB RAM - NVidia Quadro k5000
Macbook Air (2010): 2.13 Ghz Intel Core 2 Duo - 4GB RAM
chrono1081 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Looking into Programming for iOS-- just a couple of questions. mousouchop iPhone/iPad Programming 9 Apr 25, 2014 11:06 AM
Recommendations for a text editor for programming? ravenvii Mac Programming 23 Apr 24, 2013 01:21 AM
New to Programming (On a Mac; Questions) xShane Mac Programming 10 Jan 21, 2013 09:24 PM
GLKit programming reference - something good KnightWRX iPhone/iPad Programming 5 Aug 17, 2012 12:45 PM
Good resources for Cocoa programming kaworu1986 Mac Programming 9 Jul 23, 2012 02:22 PM

Forum Jump

All times are GMT -5. The time now is 02:11 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC