Meet Google Foobar

March 7, 2022

Late one night, after a bout of code slinging on a side project, a message from the upside-down popped up on my screen. My browser window parted like the seas to reveal a cryptic graphic, inviting me to participate in a coding challenge from Google. The challenge, called Foobar, is Google's way of identifying programmers with the skill-sets the company needs. Google scans your search history for software related phrases and if your recent history indicates a level of proficiency in an area, they invite you to give the challenge a go. Smart and creepy, in a Googley way.

If you complete the challenge, you are flagged as a potential hire and could be contacted by a recruiter. Nice! So, what do these challenges entail? And what programming chops do you need to get through them? Let's take a look.

There are five levels within the challenge with varying levels of difficulty. Each level presents you with one or more coding quizzes. You are allotted between 7 to 25 days to post your answer. You must successfully complete a quiz before moving on to the next one. Simple, right?

Languages and Skills

Google expects a solution in Java or Python. So, at a minimum, you should have a working knowledge of either one. You don’t require advanced programming skills, but you do need to be comfortable with methods, loops and basic arithmetic operations within your chosen language.

The challenge tests your skill with mathematical logic, data structures, algorithms and number series. I found the mathematical part of the quizzes were the hardest, since I haven’t looked at a Math textbook in a long time. And without a CS background I lacked a quiver of algorithms I could turn to when unpacking a problem. Eventually, I did land the right algorithm, but only after much searching and trial and error. I advice future participants to brush up on your basic Algorithms-101 course before you take the plunge. It's well worth the preparation.

Recursion will also play a big part of your solutions. More than one challenge involves large numbers, in the order of 10^100. At this range, looping through each state will time out your code. Using recursion to leap-frog through multiple states in your code will help you get there faster.

Hidden Test Cases

One more thing. Your code is run against pre-defined test cases as well as hidden test cases. Every quiz was tested against 10 test cases. Two were pre-defined in the problem statement, but eight tests were hidden, which means you don't know what inputs are applied to your solution. This elevates the difficulty up a notch because you're only told if your solution passes or fails against the test, but not why.

I've read of people brute-forcing their way to uncovering the hidden test, but this isn't the best approach. A better approach is to think through all the edge cases of the problem, minimums, maximums or infinite loops, and handle these scenarios as best as you can. If nothing works, go ahead and search for one online. Programmers more talented than me have posted some possible test cases, and they were helpful many times.

Some Tips

I’ll post some of the challenges here along with hints on how to proceed. If you have a question on a challenge, or need help reviewing your code, don't hesitate to contact me on Twitter at @sandeep_gopal or via the contact page.