The First Challenge

Good news: Foobar isn’t a Trojan horse designed to wreck my computer.

Better news: I get to practice Java!

Bad news: Why can’t it be MatLab?

So Foobar is a Google project that allows users to try their hand at various coding challenges. They provide the prompt and a place to type your code. You can run it against hidden test cases and then submit it. The code has to be written in either Java or Python.

Speculation abounds on the internet what this is for. Some say it’s a hiring push by Google for Java/Python coders, and others say that it’s just an Easter egg they threw into the search engine. Personally, I don’t care. It’s fun and allows me to practice my new Java skills.

The console started by telling a story of Commander Lambda’s plan to destroy Bunny Planet by aiming a DOOMSDAY weapon at the planet. As a fearless rebel spy, I must work my way up the minion totem pole by completing coding challenges to defeat her (some one at Google has too much time on their hands).

I pulled up the list of files on the command prompt: journal.txt and start_here.txt. That seemed like a good place to start. I pulled up the start here document:

Type request to request a challenge. Type help for a list of commands.

Also fairly straight forward. I typed request in to my console. Suddenly a timer appeared in the bottom left side of the console, and I finally started my first Foobar challenge.


The Problem Set Up

This challenge was fairly straight forward. The goal was to make a program that would bring in a bunch of random integers (counting numbers), bring in another number representing the maximum number of times an individual number can show up in the list, and spit out a list that gets rid of those numbers that show up too often.

That’s a lot there, so let’s break that down. The particular type of list that Google passes in and asks us to return is called an array. An array can look like {1,2,3,3,4,5}, {14,25,82,1}, or any other set of positive, whole numbers. If we look at the first array and ignore any numbers that show up more than once, the program would return {1,2,4,5} effectively disregarding the 3 and not changing the order of the original array.


Designing the Solution

So how do we solve this? Well…

  1. We need to go through the array and know what numbers show up and how often they show up.
  2. We need to create a new list that only adds a number if it shows up no more than our maximum number.

Not too bad. My method made use of hashmap which is a data structure that stores a key (in this problem, the number) and a value (the number of times the number appears). Every time a number appears, add one to the count value. I can then build a solution that reads from the input array and only adds the number to my output array if it’s counts are less than the maximum number.

 

I would like to stress this is one solution to this type of problem. There are loads of possible solutions with many being more optimal than mine. I’m interested to see the dialog that comes up discussingout different or better approaches to this problem. I truly believe programming is collaborative process, and that presenting one solution isn’t against the spirit of the challenge.


Lessons Learned

The single biggest lesson during this challenge was the power, use, and implementation of a HashMap for a project. HashMaps allow for incredibly fast look-ups for data and are often used when frequencies are asked for. Beyond that, looking into Java’s Collection interface gave me a better look at how to group data beyond an array or matrix.


This first challenge was fairly simple, and they gave a full 2 days to complete it. After, coding that up on my laptop, I transferred the file to the console and ran their verify command. VERIFYING SOLUTIONS…… ALL TEST CASES PASSED! Awesome! No clue what the test cases were, but who am I to argue with my rebel leaders?

Step two was submit the solution file.  My finger hovered above the enter key as the console asked ARE YOU SURE YOU WANT TO SUBMIT THIS SOLUTION? What if this isn’t optimal? What if it doesn’t submit right? What if I’m just wrong? For an anonymous, “fun” challenge, there was suddenly a lot of doubt and fear that became associated with it.  I took a breath and hit the enter key:

untitled.png

The ASCII buny hopped back and forth across my console. I had finished my first challenge! One down, many more to go. I’m hungry for the next one! For now, I think it’s time for a quick break.

 

 

 

Advertisements

One thought on “The First Challenge

  1. Brilliant writing style.
    One thing popped into my mind; what is the possibility that Google is using you to help train its AI/ a DNN?!
    Too cool

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s