Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › How to prepare for programming job test?
New Posts  All Forums:Forum Nav:

# How to prepare for programming job test?

There's a job that I'd really like to get and I have already had an interview for it which went really well. There has also been a programming test which I failed.

Apparently no one else managed to pass it as the company has re-advertised the position, and thanks to my good interview performance I am allowed to take the test again, and will be assessed based on the average score of both tests, so I need to perform decently.

I have done and passed a number of similar tests in the past however this one is a bit different and has probably been created by programming nerds rather than people from HR department. It consists of three open questions where you need to write a code solving particular problem using any programming language (C, C#, Java) or pseudo-code.

The three questions I remember from last time were something like these:
Quote:
1. Write a function that given a two-dimensional array [x, x] checks if it is a magic square and returns true or false. A square is magic when the sum of all the numbers in each of the sequences vertically, horizontally and diagonally is the same. http://mathworld.wolfram.com/MagicSquare.html

2. Write a function that given a point (x, y) and a radius (r) turns on all the pixels of the screen of dimensions 1024x768 that are inside of the circle.

3. Given a integer array of size n, write a function that returns the highest sum of any sub-sequence of this array (so it sums elements 1,2,3,...,n then 1,2,3,...,n-1, then 1,2,3,...,n-2, then 2,3,...,n and so on and returns the highest result.) This one was actually the only one I think I got right.

Can you recommend any kind of resources, books and/or exercises that would help me to prepare for this kind of test. I'd really like to get the job, but, even though I have some programming experience, these are not the kind of problems I deal with on regular basis, especially in higher level languages where most of this kind of stuff is done for you. Thanks.
 buka (17 items)
 buka (17 items)
Based on the questions you posted, I'm not sure that I know of a way to 'study' for it unfortunately. The questions that they asked seem to be designed to test general programming knowledge and the ability to come up with algorithms to solve problems.

I'm not sure how to get improve that type of skill other than experience. As such, one idea might be getting a programming book, C or Java or whatever you have experience with, and working example problems. The more you are forced to come up with algorithms the easier it becomes.
Edited by Xazen - 4/6/11 at 11:10am
 Scream Machine (9 items)
CPUMotherboardGraphicsRAM
i7-4770K Gigabyte Z87X-UD3H EVGA GTX 780 16GB DDR3
Hard DriveCoolingOSMonitor
256GB Samsung 840 Pro Kraken X60 Windows 7 Shimian 2560x1440
Case
Phantom 630
 Scream Machine (9 items)
CPUMotherboardGraphicsRAM
i7-4770K Gigabyte Z87X-UD3H EVGA GTX 780 16GB DDR3
Hard DriveCoolingOSMonitor
256GB Samsung 840 Pro Kraken X60 Windows 7 Shimian 2560x1440
Case
Phantom 630
As someone who has written and administered such tests to see what job applicants can offer, I'll list some advice and some things I look for during the test. Of course, every company is different, but this is how I do it.

Familiarity with data structures:I'm more likely to pick someone who can use the right data structure for the task. Someone who correctly uses a HashMap or Dictionary will score much higher than someone who uses a plain List when a Dictionary would be a much better option. Most programmers can handle basic arrays or lists but knowing how and when to use other structures is very helpful.

Code Readability: Good comments and variable naming conventions are extremely helpful. Since this is a test, comments describing your thought process are valuable even though they wouldn't be used in production code. Make good use of whitespace, and be consistent. If your code is easy to read you'll work better in a team environment. Here's a bad example based on what I've seen from applicants before:
Code:
using System;

using System.Text;
using System.Collections.Generic;

public class Sample
{
public static         void Main(string [   ]  args
)
{
Console.WriteLine("Sample code");

Console.WriteLine("More sample code")   ;
}
}


Yes, I've actually had applicants write code like that. Not only is it hard to read but it's very unprofessional. I don't care how awesome a programmer you are, I will never select someone who writes code that looks like that.

Environment and Frameworks: Make sure you're comfortable or at least somewhat familiar with the development environment (Visual Studio, Eclipse, etc.) and the framework you select (Java, NET). I've had applicants who helped teach Java using Eclipse and NetBeans at the local university as graduate assistants who, when tested, proved unable to even start a new project in Eclipse or use the correct signature for the main function or entry point of the application! If you can't do that kind of stuff from memory then you're probably in over your head.

Placeholder Code: Sometimes you get stumped on implementing part of the test. Placeholder functions are better than nothing, at least it shows you can plan and organize. If you have time and figure it out you can easily work on implementing that function later. For example, if you're supposed to sort a collection and filter out all objects that meet certain criteria, a method like this is a good start:
Code:
// Placeholder method.
private List<string> filterAndSort(List<string> input)
{
return input;
}


Code Organization: Organizational skills are very important when programming. Break a task into simpler subtasks and implement each as its own function. It's easier to read and follow, which means it's easier to maintain. Huge monolithic classes or functions usually show a lack of organizational skills. Real-world projects are often huge, in the tens or hundreds of thousands of lines of code. Being able to break it down into simpler units is an extremely valuable skill.

Asking the right questions: I don't mind if they ask me questions during the test, but I pay close attention to what they ask. If they're asking me which data structure to use, how to search an array, whether to use String or string, what's the name of a library function to do this-or-that, or why they can't get their code to compile, that counts against them. I need a programmer who can make decisions and solve problems on his own most of the time, otherwise if I hire him I might spend too much time babysitting. If, however, they're asking for clarifications on requirements, for example I said "Remove all products with a price between $1.00 and$2.00" and they ask "How do I handle objects which have a price of exactly $1.00 or$2.00?" that shows attention to detail, awareness that many bugs come from edge conditions, and that they want to get it right, and that increases their score. Another good example is "Can I use LINQ for all the filtering and sorting?" On that topic, using existing library code well is better than trying to write your own clever implementation of whatever the task is. Someone who uses three lines of LINQ code to perform the entire task will score much higher than someone who has 150 lines of code that manually loops over an array and checks and removes items.

Speed: This is more a measure of experience and confidence rather than raw development talent. The best applicants usually finish the test very quickly while still having a correct or nearly-correct implementation. They will score much higher than someone who gets a 100% correct implementation but takes ten times as long to get there.

Also, remember to just do the best you can and don't worry if you can't get something down. In my experience applicants will rarely get everything right or get a 100% effective solution for all my test cases. Even if you feel really bad about the test, it's possible you did better than everyone else and are competent and fitting for the job.

Those are the biggest things I can think of right now, I'll post later if something else comes to mind.

Hope that helps.
Edited by mott555 - 4/6/11 at 9:19am
Listen to what mott555. The questions are fairly self explanatory and seem like something I could have done simply in college outside of question two. Though that's just because I have no idea how to accomplish turning off or on pixels. If you are allowed to reference a function you didn't make that does that for you than its really pretty simple and just a test of your basic programming and logical problem solving skills.

You said the language doesn't matter or you could use pseudo-code which means that this is what I mentioned at the end of the last paragraph. Just make sure you use the appropriate data types, stick with one language, and make sure your solution doesn't have obvious errors. Eloquence is probably a secondary need for a test like this.

Edit: Especially remember the code readability part. I get angry just looking at that bad code mott555 wrote. The framework importance will depend on where you work. I'm never required, and in fact discouraged, from creating new projects in the solutions I work on. That would be less likely in a smaller company where decisions like that don't have to go through a higher up. I'd have to go back over a few thing to start a new solution or project but like me you should at least be familiar enough that you could figure it out with a quick Google refresher. Which means do a similar refresher before you meet so you remember it just in case. Good luck!
Edited by Kirmie - 4/6/11 at 9:28am
 My giant (13 items)
CPUMotherboardGraphicsRAM
E6600 lapped Asus P5n32-E 680i GeForce 9800GT 512MB 2x1GB (unused ATM) & 2x2Gb Corsair XMS2 PC6400
Hard DriveOSMonitorPower
WDJS SATA-II 160GB + WD80GB + WDAAKS Raid0 320GB Aperature FSII 19" LCD Apevia DarkSide 600W
Case
NZXT Zero
 My giant (13 items)
CPUMotherboardGraphicsRAM
E6600 lapped Asus P5n32-E 680i GeForce 9800GT 512MB 2x1GB (unused ATM) & 2x2Gb Corsair XMS2 PC6400
Hard DriveOSMonitorPower
WDJS SATA-II 160GB + WD80GB + WDAAKS Raid0 320GB Aperature FSII 19" LCD Apevia DarkSide 600W
Case
NZXT Zero
Those are pretty basic questions. Besides Hello World, I'm not sure you can get much more basic. (A slight exaggeration) I wish you luck on the exam, and hope you pass if that's what you want, but does this company know that they're hiring someone with virtually no applicable programming experience?

Of course, that could always change. You could always learn, but it's not something that you learn overnight. Like most things, it takes (at least) many years of programming all of the time to firmly grasp all of the concepts. It takes ten times as long to become an expert.

I just hope you know what you're getting yourself in to. Of the three languages you suggested doing that in, I would probably recommend Java as it's the easier of the three. C# is very similar and is probably just as easy. So I'd start by buying a beginner book for one of these two languages and reading the whole thing from start to finish, making sure to do every exercise.

edit: To clarify my obvious intentional over-exaggeration for some people.
Edited by Plex - 4/6/11 at 10:51am
 Intellect v2 (9 items)
CPUMotherboardGraphicsRAM
Intel Core i7-6700K Processor ASUS ROG MAXIMUS VIII HERO LGA1151 DDR4 M.2 SAT... EVGA GTX 1080 SC ACX 3.0 Crucial Ballistix Sport 32GB DDR4 2400 MT/s (PC...
CoolingKeyboardPowerCase
Noctua NH-D15 Das Keyboard 4 Professional (Brown) Corsair AX860 Fractal Design Define R5
Mouse
MIONIX NAOS 7000
 Intellect v2 (9 items)
CPUMotherboardGraphicsRAM
Intel Core i7-6700K Processor ASUS ROG MAXIMUS VIII HERO LGA1151 DDR4 M.2 SAT... EVGA GTX 1080 SC ACX 3.0 Crucial Ballistix Sport 32GB DDR4 2400 MT/s (PC...
CoolingKeyboardPowerCase
Noctua NH-D15 Das Keyboard 4 Professional (Brown) Corsair AX860 Fractal Design Define R5
Mouse
MIONIX NAOS 7000
Quote:
Originally Posted by Plex;13024543
Those are really, really, reeeeally easy questions. Besides Hello World, I'm not sure you can get much more basic. I wish you luck on the exam, and hope you pass if that's what you want, but does this company know that they're hiring someone with virtually no applicable programming experience?

Of course, that could always change. You could always learn, but it's not something that you learn overnight. Like most things, it takes (at least) many years of programming all of the time to firmly grasp all of the concepts. It takes ten times as long to become an expert.

I just hope you know what you're getting yourself in to. Of the three languages you suggested doing that in, I would probably recommend Java as it's the easier of the three. C# is very similar and is probably just as easy. So I'd start by buying a beginner book for one of these two languages and reading the whole thing from start to finish, making sure to do every exercise.

I am not a great programmer or anything, but to compare those questions with the 'Hello world' apps is a little bit far fetched. I just don't want this to be a "Let's get down on this n00bs skillz" thread.
 Leroy Brown (16 items)
CPUMotherboardGraphicsGraphics
i7 950 ASUS Rampage III Gene EVGA GTX480 EVGA GTX480
RAMHard DriveHard DriveOptical Drive
Mushkin Enhanced Redline Mushkin Callisto Deluxe Western Digital Scorpio Black LG Blu-Ray Burner
CoolingOSMonitorKeyboard
Corsair H50 Win 7 64bit Auria 24" 1080p i-rocks RF-6520-BK
PowerCaseMouse
Corsair HX850 NZXT Vulcan Logitech G700
 Leroy Brown (16 items)
CPUMotherboardGraphicsGraphics
i7 950 ASUS Rampage III Gene EVGA GTX480 EVGA GTX480
RAMHard DriveHard DriveOptical Drive
Mushkin Enhanced Redline Mushkin Callisto Deluxe Western Digital Scorpio Black LG Blu-Ray Burner
CoolingOSMonitorKeyboard
Corsair H50 Win 7 64bit Auria 24" 1080p i-rocks RF-6520-BK
PowerCaseMouse
Corsair HX850 NZXT Vulcan Logitech G700
Quote:
Originally Posted by Dunkler;13024638
I am not a great programmer or anything, but to compare those questions with the 'Hello world' apps is a little bit far fetched. I just don't want this to be a "Let's get down on this n00bs skillz" thread.

They are basic questions. I'm not "getting down" on anyone's skills, mind you. If anyone is going to derail the thread into that, it's your post right there.

My concern for the OP is that there are three levels of programmer jobs. Entry level, mid-level, and senior. This exam seems like it's targeted toward an entry level position applicant, but I could be mistaken. It's one thing to be a programmer who is in the middle of learning, figuring out his/her mistakes and improving. It's another to come here and be like "hey here's some questions, how can I not fail this test again?" Like I said, I hope that the OP is able to grasp what he needs to before this test, and I hope that he passes. I'm the last person to "get down" on anyone's skills. I certainly wouldn't talk like a moron (e.g. n00bs, skillz, etc.) either. I go out of my way to help beginners on here all of the time.
 Intellect v2 (9 items)
CPUMotherboardGraphicsRAM
Intel Core i7-6700K Processor ASUS ROG MAXIMUS VIII HERO LGA1151 DDR4 M.2 SAT... EVGA GTX 1080 SC ACX 3.0 Crucial Ballistix Sport 32GB DDR4 2400 MT/s (PC...
CoolingKeyboardPowerCase
Noctua NH-D15 Das Keyboard 4 Professional (Brown) Corsair AX860 Fractal Design Define R5
Mouse
MIONIX NAOS 7000
 Intellect v2 (9 items)
CPUMotherboardGraphicsRAM
Intel Core i7-6700K Processor ASUS ROG MAXIMUS VIII HERO LGA1151 DDR4 M.2 SAT... EVGA GTX 1080 SC ACX 3.0 Crucial Ballistix Sport 32GB DDR4 2400 MT/s (PC...
CoolingKeyboardPowerCase
Noctua NH-D15 Das Keyboard 4 Professional (Brown) Corsair AX860 Fractal Design Define R5
Mouse
MIONIX NAOS 7000
OP: Here's a great book to start with:
[ame="http://www.amazon.com/Java-Beginners-Guide-4th-ebook/dp/B001GCUCXG/ref=sr_1_1?ie=UTF8&m=AG56TWVU5XWC2&s=digital-text&qid=1302113007&sr=1-1"]Amazon.com: Java: A Beginner's Guide, 4th Ed. eBook: Herbert Schildt: Kindle Store[/ame]

It's only $20 for the Kindle version. If you happen to have a Kindle/iPhone/Android/iPad, etc. I think you can actually read it on a Kindle PC app now, too. Anyway, I can vouch for it. Great book. Everything that you learn that you don't need for the exam will help you tremendously after you land the job.  Intellect v2 (9 items) CPUMotherboardGraphicsRAM Intel Core i7-6700K Processor ASUS ROG MAXIMUS VIII HERO LGA1151 DDR4 M.2 SAT... EVGA GTX 1080 SC ACX 3.0 Crucial Ballistix Sport 32GB DDR4 2400 MT/s (PC... CoolingKeyboardPowerCase Noctua NH-D15 Das Keyboard 4 Professional (Brown) Corsair AX860 Fractal Design Define R5 Mouse MIONIX NAOS 7000  Intellect v2 (9 items) CPUMotherboardGraphicsRAM Intel Core i7-6700K Processor ASUS ROG MAXIMUS VIII HERO LGA1151 DDR4 M.2 SAT... EVGA GTX 1080 SC ACX 3.0 Crucial Ballistix Sport 32GB DDR4 2400 MT/s (PC... CoolingKeyboardPowerCase Noctua NH-D15 Das Keyboard 4 Professional (Brown) Corsair AX860 Fractal Design Define R5 Mouse MIONIX NAOS 7000 Where do you get stuck? The more we know, the better we can help Are you comfortable with the 'approach' and not the implementation? 1. A magic square has the same sum along the two main diagonals, each column and each row. How do we test for this property? Well: grab a row, or a column, or a diagonal and test all of the other options! Not uninterestingly, matlab is beautiful at this. Code: M =[...;...] %someTestSquare magicConstant = sum(M(:,1)) %first column for i=1:n if magicConstant != sum(M(:,i)); %the i'th column return false end if magicConstant!=sum(M(i,:)); %the i'th row return false end end %Now test diagonal: diag1Sum = 0; diag2Sum = 0; for i=1:n diag1Sum = diag1Sum +M(i,i); diag2Sum = diag2Sum + M(n-i +1,n-i +1); end return diag1Sum == diag2Sum==magicConstant  2. Write a function that given a point (x, y) and a radius (r) turns on all the pixels of the screen of dimensions 1024x768 that are inside of the circle. Hey! Polar coordinates look beautiful here! definition of a circular plane in polar? 0<\theta<2\pi So for every r and every theta less than R and 2*pi, respectively, we should draw on the screen. Let's assume we can simple draw a point? Depending on the language and the canvas/drawable setup, you may have an easier task or a harder one... Because only CoffeeScript can compete with python's for loop syntax, a bit of python Code: def drawCircle(xStart,yStart,R): numSects = 200 #arbitrary, 200 sections of 2Pi are more than enough piIncrement = 2*math.pi/numSects for r in range(1,R): #radius in pixels for theta in range(numSects): %theta is theta *2*pi/numSects drawPoint(r*math.cos(theta*piIncrement),r*math.sin(theta*piIncrement))  3. Given a integer array of size n, write a function that returns the highest sum of any sub-sequence of this array (so it sums elements 1,2,3,...,n then 1,2,3,...,n-1, then 1,2,3,...,n-2, then 2,3,...,n and so on and returns the highest result.) This one was actually the only one I think I got right. There is obviously a 'brute' force approach, there are, however, other options, as well. Perhaps if I finish this problem set, I will come back to this. There is almost certainly a very interesting and efficient algorithm that can be employed. Edited by wcdolphin - 4/6/11 at 11:37am  For sale (13 items) CPUMotherboardGraphicsRAM i7-920 Asus P6T Deluxe Asus GTX460 TOP 768mb G Skill ECO 1600 CAS7 1.35V Hard DriveOptical DriveOSMonitor 2x Vertex 60 GB raid[0] Asus DVDRW W7,Ubuntu 2 xAsus VH236H KeyboardPowerCaseMouse Pad Razer Ultra X3 1000W HAF 932 My Desk  For sale (13 items) CPUMotherboardGraphicsRAM i7-920 Asus P6T Deluxe Asus GTX460 TOP 768mb G Skill ECO 1600 CAS7 1.35V Hard DriveOptical DriveOSMonitor 2x Vertex 60 GB raid[0] Asus DVDRW W7,Ubuntu 2 xAsus VH236H KeyboardPowerCaseMouse Pad Razer Ultra X3 1000W HAF 932 My Desk Warning: Spoiler! (Click to show) Quote: Originally Posted by mott555;13023625 As someone who has written and administered such tests to see what job applicants can offer, I'll list some advice and some things I look for during the test. Of course, every company is different, but this is how I do it. Familiarity with data structures:I'm more likely to pick someone who can use the right data structure for the task. Someone who correctly uses a HashMap or Dictionary will score much higher than someone who uses a plain List when a Dictionary would be a much better option. Most programmers can handle basic arrays or lists but knowing how and when to use other structures is very helpful. Code Readability: Good comments and variable naming conventions are extremely helpful. Since this is a test, comments describing your thought process are valuable even though they wouldn't be used in production code. Make good use of whitespace, and be consistent. If your code is easy to read you'll work better in a team environment. Here's a bad example based on what I've seen from applicants before: Code: using System; using System.Text; using System.Collections.Generic; public class Sample { public static void Main(string [ ] args ) { Console.WriteLine("Sample code"); Console.WriteLine("More sample code") ; } }  Yes, I've actually had applicants write code like that. Not only is it hard to read but it's very unprofessional. I don't care how awesome a programmer you are, I will never select someone who writes code that looks like that. Environment and Frameworks: Make sure you're comfortable or at least somewhat familiar with the development environment (Visual Studio, Eclipse, etc.) and the framework you select (Java, NET). I've had applicants who helped teach Java using Eclipse and NetBeans at the local university as graduate assistants who, when tested, proved unable to even start a new project in Eclipse or use the correct signature for the main function or entry point of the application! If you can't do that kind of stuff from memory then you're probably in over your head. Placeholder Code: Sometimes you get stumped on implementing part of the test. Placeholder functions are better than nothing, at least it shows you can plan and organize. If you have time and figure it out you can easily work on implementing that function later. For example, if you're supposed to sort a collection and filter out all objects that meet certain criteria, a method like this is a good start: Code: // Placeholder method. private List<string> filterAndSort(List<string> input) { return input; }  Code Organization: Organizational skills are very important when programming. Break a task into simpler subtasks and implement each as its own function. It's easier to read and follow, which means it's easier to maintain. Huge monolithic classes or functions usually show a lack of organizational skills. Real-world projects are often huge, in the tens or hundreds of thousands of lines of code. Being able to break it down into simpler units is an extremely valuable skill. Asking the right questions: I don't mind if they ask me questions during the test, but I pay close attention to what they ask. If they're asking me which data structure to use, how to search an array, whether to use String or string, what's the name of a library function to do this-or-that, or why they can't get their code to compile, that counts against them. I need a programmer who can make decisions and solve problems on his own most of the time, otherwise if I hire him I might spend too much time babysitting. If, however, they're asking for clarifications on requirements, for example I said "Remove all products with a price between$1.00 and $2.00" and they ask "How do I handle objects which have a price of exactly$1.00 or \$2.00?" that shows attention to detail, awareness that many bugs come from edge conditions, and that they want to get it right, and that increases their score. Another good example is "Can I use LINQ for all the filtering and sorting?" On that topic, using existing library code well is better than trying to write your own clever implementation of whatever the task is. Someone who uses three lines of LINQ code to perform the entire task will score much higher than someone who has 150 lines of code that manually loops over an array and checks and removes items.

Speed: This is more a measure of experience and confidence rather than raw development talent. The best applicants usually finish the test very quickly while still having a correct or nearly-correct implementation. They will score much higher than someone who gets a 100% correct implementation but takes ten times as long to get there.

Also, remember to just do the best you can and don't worry if you can't get something down. In my experience applicants will rarely get everything right or get a 100% effective solution for all my test cases. Even if you feel really bad about the test, it's possible you did better than everyone else and are competent and fitting for the job.

Those are the biggest things I can think of right now, I'll post later if something else comes to mind.

Hope that helps.

Thanks. Good points. +rep

The main thing is though that I have no one to speak with during the test and I can't use any IDE or google. I'm pretty much only given a PC without Internet connection and a notepad (actually gedit), and need to write everything from the top of my head.

Also I'm not exactly allowed to use any language specific libraries that would do the job for me. So for example in the circle question I can't just use
Code:
if (point.distanceTo(center) < radius) {...}

but rather have to come up with a formula to calculate the distance and write my own code for it. So the more appropriate answer would be something like:
Code:
struct point {
int x;
int y;
} pt, center;

void paintCircle (int x,int y, double radius) {

center.x = x;
center.y = y;

//for each point pt on the screen

if (sqrt((double)(center.x - pt.x) * (center.x - pt.x) + (double)(center.y -pt.y) * (center.y - pt.y)) < radius) {
//turn it on
};
}

And I'm still not sure if that would be the most computationally efficient solution since the function has to iterate through all the points on the screen.

Now I'm not asking for solutions to the problems, as with google and not being timed I can come up with them on my own. My main issue is how to prepare for such test and what kind of books/resources on algorithms and data structures (rather than language specific stuff) would you recommend.

I'm currently working through the exercises in Kernighan and Ritchie C book as it does provide some pretty good examples.
Edited by poroboszcz - 4/6/11 at 1:24pm
 buka (17 items)
 buka (17 items)
New Posts  All Forums:Forum Nav:
Return Home
Back to Forum: Coding and Programming
• How to prepare for programming job test?
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › How to prepare for programming job test?