The Foobar problem is a coding take a look at hosted by Google that may be accomplished in both Python or Java. I accomplished the problem utilizing Python. The problem has its personal server with particular, terminal-style instructions.

Google Foobar problem invitation. | Screenshot: Katy Hagerty

So as to add some enjoyable, it’s house themed. The evil Commander Lambda has kidnapped house bunnies, and it’s essential to rescue them. Every downside provides extra context to the backstory. The issues are of assorted issue and are organized into 5 ranges. Every query should be solved inside a sure time restrict. Extra time is given for the upper ranges.

What Is the Google Foobar Problem?

The Google Foobar problem is a coding take a look at administered by Google that consists of 5 ranges and will be accomplished in both Python or Java. The problem has been used to guage and recruit potential engineers for Google. There are two methods to take part: Google extends an invite over the browser otherwise you obtain an invite code.

I discovered the degrees one, two and three issues just like LeetCode issues, each by way of issue and construction. The issues had been simple and infrequently required optimizing code for pace. However, ranges 4 and 5 had been extra sophisticated and layered a number of ideas into one downside.


Methods to Take part within the Foobar Problem? 

There are two methods to take part within the problem:

  1. Google extends an invite by the browser.
  2. A good friend sends you an invite code.

I got here throughout the problem by the primary technique. I used to be Googlingrecord comprehension” for a special article, and my browser unfolded to disclose the invitation. I had by no means heard of the Foobar problem earlier than and was a bit of circumspect. After verifying that this was a reliable problem, I accepted.

For sure, the factor of shock piqued my curiosity within the problem. To not point out, Google reaching out to me with an unique invite positively gave me a confidence increase as a developer. I noticed this as a name to journey and instantly needed to dedicate all my consideration to it.

For the second technique, you want a good friend to ship you an invite code. One invitation code is given after finishing stage two. One other is given after finishing stage 4.

Extra on Software program Engineering: Job Interview Questions Meta Asks Software program Engineers


Does Google Use the Problem for Recruiting? 

At one level, Google used the problem to seek out new expertise. You’ll discover many individuals on-line who had a Google recruiter attain out one or two days after finishing the problem. Nonetheless, it seems that Google hasn’t used the problem for hiring since 2020.

After ending stage three, the Foobar server asks if you wish to present your contact data to a Google recruiter. I offered my data however by no means heard from them.

Nonetheless, I nonetheless consider this problem is worth it. It’ll expose you to new coding ideas, sharpen your expertise, and finally, make you a greater developer.


Google Foobar Suggestions 

Google offers a constraints.txt file, nevertheless it isn’t very detailed. For example, it states all customary libraries are allowed with just a few listed exceptions. Nonetheless, math and numpy aren’t allowed regardless that these are frequent libraries. To check which libraries had been allowed, I imported the library, returned the reply of one of many take a look at instances after which verified the answer. If the answer handed the one take a look at case, the library was acceptable.

# Trick to check if library is allowed
import numpy as np

def answer(n):
  return 1

Additionally, remark out all print statements earlier than verifying the code. Any print statements will trigger the take a look at instances to fail.

The problem may be very specific about enter and output sorts. If the issue assertion asks for a particular enter or output kind, make sure that to produce the right kind.

Lastly, I didn’t have any expertise with Python 2.7 previous to this problem. In actual fact, I examined lots of my options for the decrease stage issues in Python 3. This got here again to chunk me later within the problem. Particularly, I used to be not conscious that in Python 2.7.13, / operator performs integer division if the inputs are integers. For example:

# Integer division in Python 2.7.13
a = 5
b = 2
print(a / b)

Nonetheless, in Python 3, / performs float division.

# Float division in Python 3
a = 5
b = 2
print(5 / 2)


Google Foobar Questions and Ideas 

Beneath, I breakdown the questions and clarify my thought course of. I additionally present options. Nonetheless, I extremely advocate you try the issue first. The very best a part of the problem is the shock and satisfaction of fixing an elusive downside.

I debated not posting options and simply explaining the underlying ideas. Nonetheless, a part of coding is studying the right way to troubleshoot and pinpointing the place the code fails. Thus, I made a decision to publish options in order that if you happen to’re caught, you may see precisely the place your logic diverges.


Google Foobar Stage 1: Drawback 1 

The Set Up

I Love Lance & Janice

“You’ve caught two of your fellow minions passing coded notes forwards and backwards — whereas they’re on responsibility, no much less! Worse, you’re fairly positive it’s not job-related — they’re each enormous followers of the house cleaning soap opera “”Lance & Janice””. You understand how a lot Commander Lambda hates waste, so if you happen to can show that these minions are losing her time passing non-job-related notes, it’ll put you that a lot nearer to a promotion.

Happily for you, the minions aren’t precisely superior cryptographers. Of their code, each lowercase letter [a..z] is changed with the corresponding one in [z..a], whereas each different character (together with uppercase letters and punctuation) is left untouched. That’s, ‘a’ turns into ‘z’, ‘b’ turns into ‘y’, ‘c’ turns into ‘x’, and so on. For example, the phrase “”vmxibkgrlm””, when decoded, would develop into “”encryption””.

Write a operate referred to as answer(s) which takes in a string and returns the deciphered string so you may present the commander proof that these minions are speaking about “”Lance & Janice”” as an alternative of doing their jobs.”



  • To supply a Python answer, edit
  • To supply a Java answer, edit


Check Circumstances


(string) s = “wrw blf hvv ozhg mrtsg’h vkrhlwv?”


(string) “did you see final evening’s episode?”


(string) s = “Yvzs! I xzm’g yvorvev Lzmxv olhg srh qly zg gsv xlolmb!!”


(string) “Yeah! I can’t consider Lance misplaced his job on the colony!!”

Use confirm [file] to check your answer and see the way it does. When you’re completed modifying your code, use submit [file] to submit your reply. In case your answer passes the take a look at instances, it will likely be faraway from your own home folder.

A tutorial on the right way to full the Google Foobar problem. | Video: srcmake

Extra on Software program Engineering: Will the Whiteboard Check Grow to be a Factor of the Previous?


Methods to Remedy Google Foobar Stage 1

Coincidentally, I not too long ago constructed an app for a shift cipher and this downside instantly jogged my memory of that. Solely the lowercase characters should be deciphered. The opposite characters stay unchanged. First, create a dictionary to retailer the encoded characters and their deciphered counterparts. Subsequent, use a for loop to iterate by each character within the enter string. If the character is lowercase, pull its deciphered worth from the dictionary. If not, add the character to the reply string.

In my view, this downside was designed to check the participant’s data of the str and dict knowledge sorts and their built-in strategies.  

Leave a comment

Your email address will not be published. Required fields are marked *