Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

So I'm in the process of looking for a job. And I have had plenty of test and just recently someone sent me a puzzle.

It's the crackless wall problem and I have no idea how to approach it. I could cheat and google the answer, but I'm an honest fellow and it's taken me 2 days and still no solution. Also performance is a key issue as well.

Should I take some time to master solving programming puzzles? Or should I focus on learning the language first, then master optimization techniques? I'm having issues choosing the best approach.

Just today I found out from a previous interview that they chose someone else over me because that candidate seemed more knowledgeable than me because during the technical interview this candidate was a bit more snappy with his/her responses.

I knew all the answers but I wasn't fast enough with them. Does this matter with all interviewers?

Should I invest time in mastering core concepts in java so I can have just as fast recall?

(To shed some light on my background: I am a recent graduate with a little over a year of java programming experience under my belt. I only have a bachelors degree. I know this is irrelevant, but I'm also 23.)

share|improve this question

migrated from stackoverflow.com Aug 10 '11 at 3:22

This question came from our site for professional and enthusiast programmers.

    
What was the job you were looking for again? –  André Puel Aug 10 '11 at 3:21
1  
Voting to move this question to programmer's stack exchange as it is more appropriate there than it is here. Original poster, please read the FAQ before posting here (or anywhere). –  Hovercraft Full Of Eels Aug 10 '11 at 3:22
    
Sorry about that HFOE... –  HunterBlack Aug 10 '11 at 3:25
    
@Andre Puel I'm trying to get a job as a java dev: junior, or mid-level. –  HunterBlack Aug 10 '11 at 3:26
2  
All things being equal, why wouldn't you pick someone who can work faster? –  JeffO Aug 10 '11 at 3:36

8 Answers 8

up vote 11 down vote accepted

In my experience I have found that, for puzzle-type interview questions, the actual answer you come up with is not as important as the process by which you came up with the answer.

Interviewers know that you are under pressure during an interview and may not be at your coding best. It's hard to code under that kind of pressure. However, if you approach the problem with a reasonable attempt at a solution and are able to reason your way through the implementation, performance implications and possible edge cases then that will help you. Try to think of the problem in real-world terms, if possible. Ask questions about the problem to find out what aspects are important. Is it OK to implement a solution that's correct but slow so you can make it fast later? Or does it need to be correct and fast right now? Optimization is a difficult task, particularly when you only have a short time to do it.

The speed with which you generate answer is probably not so important in most cases. Better to come up with a good answer slowly than a mediocre one quickly.

I believe there are essentially two types of interview question:

  1. Does the candidate know the languages they claim to know?
  2. Does the candidate know enough about programming to be able to solve a tricky problem?

For the first type you do need to be able to reply quickly. I think it's probably worth studying the language a bit more if you think your recall is too slow. For example, if you say you know Java then you'd better be able to implement some basic functions without needing to think about them too much (e.g. reverse a string, compute the Fibonacci sequence, know what types of Collection implementation are available in the core Java libraries and the pros and cons of each etc).

For the second type speed is much less important. Thoughtfulness and attention to good design are more important.

I'd stay away from the "learn each hard computer science problem and know a solution for each one" approach, because in the real world you don't get "pure" computer science problems very often. That said, it's definitely worth being able to recognise an NP-hard problem when you see it and have some idea about how to approach a solution.

Time for a grain of salt: each interviewer has their own ideas about what is important and what is not. I have said what I think is important but your mileage may vary, results not typical, consult your doctor before use etc etc.

EDIT: A couple of other things to note. Be willing to say "I don't know" when you don't know. It's hard (I'm really bad at it) but it helps. Of course, you should follow up with a reasonable attempt after you've established your lack of knowledge...depending on the question, of course.

Also, it's very helpful to be able to say "this would be easier in language X" or "with tool Y". Different tools for different jobs. If someone asks you to look through log files to obtain all requests from a particular IP address then you're going to lose major points if you try to use Java rather than grep.

share|improve this answer

I'm sorry to tell you this, but you probably don't have the programming chops required for the job you're describing. Not because you "only" have a bachelors, though---but because you've gotten a bachelors but have "only" a year or so of programming experience.

Kickarse programmers program in their own time, outside of courses. They don't need courses to tell them what to program! They program because they love it, and they find any excuse to write more code.

I was that way back when I was a student. And now, 15 years later, I'm still that way---I find any spare time I can writing code for fun, when I'm not working (or tending to daily life).

(Okay, my post was a bit harsh, and I'm sorry about that. I think if you're looking for a "mundane" programming job, what you've described of your aptitude above would probably be adequate. But such jobs wouldn't be asking you to solve algorithmic problems either. :-P)

share|improve this answer
2  
To be honest, if you put 5 years of work experience and 10 years of personal/hobby/side projects on a job application, I'd focus more on the 5 years of work experience. It's not just about how much time you've been writing code. –  JeffO Aug 10 '11 at 3:35
    
@Jeff: Well, of course. But we're talking about a fresh graduate here. –  Chris Jester-Young Aug 10 '11 at 3:36
    
Okay. I do program in my own time, thank you very much. And yes I do appreciate the tough love approach....................... –  HunterBlack Aug 10 '11 at 3:36
    
@HunterBlack: Cool. What languages do you program with for fun? (Please say Ruby, Python, Scheme, or the like, as opposed to Java, C#, PHP, or VB.) Get good with that language, and Java would be easy as pie in comparison. :-) (BTW, I'm not hating on Java; in fact, I'm quite experienced with Java, and my comments come from that place.) –  Chris Jester-Young Aug 10 '11 at 3:40
1  
@Mayra: Yes and no. As for Java itself, of course Java is the best way to practise it. However, if you have a less short-sighted view of programming (as a craft to develop over one's career), knowing other programming languages (and especially the techniques they encourage) is very useful. –  Chris Jester-Young Aug 10 '11 at 3:57

Don't focus on "programming puzzles", focus on writing code that solves problems. Write lots of code. Read lots of code; this is as important or more than writing code.

If you have spent a lot of time working with code, then writing the toy problems required in a (good company's) interview should be pretty straightforwards.

Its definitely worthwhile to spend time mastering core concepts in Java, but so that you can become a better programmer, not so you can solve trivia questions in interviews quickly.

Puzzle-type problems that focus on a "gotcha" moment are harder. A good company shouldn't ask that kind of problem since it doesn't really tell you anything about the candidate, but unfortunately a lot of them do. The best I can say is to scan the internet for the most common problems so you are familiar with their answers.

share|improve this answer

There's always brute force. It's almost never the best solution, but it's a good way to get started when you're stuck.

share|improve this answer
    
Alas, it's also a good way to flunk the interview. :-( –  Chris Jester-Young Aug 10 '11 at 4:23
2  
I don't suggest that you submit a brute force solution. (That's better than submitting nothing, though. If you can't find a better solution, at least you can show them that you know how to write code that works and you know how to make progress even when your muse is ignoring you.) What I mean here is that implementing a brute force solution can help you gain insight that leads to better solutions. For example, you might notice that you're spending a lot of time calculating the same value over and over, which leads you to an improved solution. –  William Shakespeare Aug 10 '11 at 4:47

The 3 capabilities from the headline

  • optimize code
  • solve complex puzzles
  • answer technical questions quickly

might be more important in interviews, than in the day-by-day job.

Planning, designing and organizing software often does not depend on solving tricky puzzles. 50% of the programmers I know love the puzzles and tricky questions, and so do I, but I can imagine that you can go along without it, maybe if you have some other people in the company, which you can call, if you really need it.

share|improve this answer

How important is it for a programmer to know how to optimize code, solve complex puzzles, answer technical questions quickly?

Here's my perspective from the other side of the table.

It is fairly important, but of course it depends on the hiring organization. Some positions require some ability to come up with approaches to novel problems, so solving complex puzzles would be important. You should have learned some algorithmic approaches in school: tree searches, backtracking, dynamic programming, basic graph algorithms, etc., and you should be able to apply these techniques to new problems. If you were asked to devise an algorithm in the interview, then presumably this ability is important to the hiring organization.

High-performance teams will expect you to explain basic concepts almost immediately, They expect you to be extremely familiar with those concepts, and to have used that knowledge daily for at least the past three years. In the past five years you should have written a LOT of code, thousands and thousands of lines. Basic CS knowledge and basic Java features should be as familiar as your favorite foods.

Code optimization is a complex subject, but you should have learned about calculating the order of complexity of algorithms, and you should understand the cost of basic operations like string concatenation.

Keep in mind that interviewers consider most of their questions to be fairly easy.

Sadly, some CS departments do a poor job of preparing students for the marketplace, and early interviews with selective teams can be a bit overwhelming. If that is your situation, and you are ambitious, then you will have to catch up by practicing as much as possible. Work on algorithmic puzzles available at a number of sites. Read well-reviewed books on Java or any other computer topic that interests you. Attend local technical groups to learn from more experienced people, and make contacts that may lead to an offer.

share|improve this answer

You should definitely search for and study existing solutions and complexity analyses before embarking on a new solution.

share|improve this answer

You have to do both at the same time! Programming is easy compared to those puzzles. You need to be an expert at solving puzzles like you mention. You should work on these ALL the time throughout your entire career. You need to spend your entire life working on your reasoning and problem solving skills. Don't take too long holding out before you look up the answer because there are a lot more puzzles where that one came from and you need practice. You need to study logic, numerical analysis, discrete math, etc.. I hope you saved you textbooks. Superior reasoning skills will help you succeed at everything in this industry. And, I've gotten a lot of puzzles during interviews so you can count on them.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.