Code exercises from an interview

I had a phone interview recently that lead to a couple of code exercise I was asked to complete to show my grasp of ruby and design. The job in question is fairly data heavy so these were more logic puzzles then rails specific.

I’ve made a blog post about it. Hopefully it helps give an idea of what a potential employer may ask.

Does anyone else have examples of interview questions or exercises? It would be great if you’d like to share your experiences here.

Thanks for sharing. It’s interesting to see what sorts of things employers look for in coding problems. I also posted a few specific comments about your code on your blog. I’m a fairly new Ruby programmer and noticed a couple things that I recently cleaned up in my early Ruby projects.

Kudos on doing the blog post!

I’ve been taking some of those and adding them to my “Cracking the Coding Interview” github repository in the “Other Puzzles” section. Unfortunately, some of the more interesting ones are protected by the company and thus can’t be posted (e.g., “Given a dictionary list, find the longest word in the list which is fully composed of words from that list”, or “Given a set of train routes [a directed graph problem], provide answers about shortest route, routes less than ‘n’ units, unreachable routes, …”).

Btw guys, I just recently discovered www.codewars.com. It has a lot of cool exercises in Ruby/Javascript if you’re looking for more exercises. These aren’t as involved as other ones, but quick enough that it’s fun to do and see other people’s solutions.

@gchaturvedi good suggestion. Codewars has been really helpful in learning more about ruby. I’ve had to use some ruby class methods I didn’t know previously existed.

I’d also like to suggest www.exercism.io for more programming exercises. Once you finish an exercise and submit it, it’s available to be nitpicked by others who have completed that exercise. This provides a great way to have your code reviewed by others and get some refactoring tips.

The consultancy I work for often uses www.cyber-dojo.com for pair programming style interviews. The current favourite challenge is Roman Numerals.

They like to find out how the candidate breaks down a problem and approaches the task, under the pressure of an interview situation. The candidate has already had to pass a basic coding challenge to get to this phase (e.g. submitting a solution to fizz buzz).

Assuming the candidate knows what they’re doing, what they’re really looking for is how they work, will they fit in with the team, can they clearly explain their thought process.

@jonathanmundy Is there any way of changing the ruby version, or at least testing framework on cyber-dojo? I can manage with Test::Unit, but would much rather have RSpec.

@zamith there are instructions here https://github.com/JonJagger/cyberdojo/blob/master/readme.txt for running your own cyber-dojo server.

There’s a section about adding languages and I assume you can upgrade existing languages. I’ve not tried myself (my dev team uses c#).

Oh ok. Didn’t know you could run your own server. Thanks.

I had one recently as well! Here’s the repo with the question I was given and my solution:

Looking at it now I feel like I could/should refactor it a bit since I only have one Atm class at the moment. I’m thinking there should perhaps be some sort of Transaction class that handles withdrawals and also a ValidateWithdrawal class that determines whether an amount & set of denominations can be withdrawn (since I already have a few methods dealing with that, that are ripe for extraction).

Let me know what you think! If you’re just starting out the problem might be a good one to try out.