Featured image of post FB1 - Google Foobar - Minion Work Assignments

FB1 - Google Foobar - Minion Work Assignments

Level 1: The Very First Challenge. Learn how to do it and find loopholes for easier debugging.

Context: I had a good night’s sleep before returning to this. Then I logged back into Google Foobar to do the challenge. Here is the first look at Google Foobar challenge. first look googlefoobar These are common commands to interact with Google Foobar.

  • ls: list directory contents [dir_name]
  • cd: change directory [dir_name]
  • cat: print file [file_name]
  • edit: open file in editor [file_name]
  • āŒ˜ + S: save the open file [when editor is focused]
  • verify: runs tests on solution file [file_name]
  • submit: submit final solution file for assessment [file_name]
  • request: request new challenge

first look googlefoobar

What is the first Google Foobar challenge?

This is the Level 1. The challenge is simple, isn’t it? (except it’s too long, hehe) level 1 google foobar challenge

readme.txt:

Commander Lambda’s minions are upset! They’re given the worst jobs on the whole space station, and some of them are starting to complain that even those worst jobs are being allocated unfairly. If you can fix this problem, it’ll prove your chops to Commander Lambda so you can get promoted!

Minions’ tasks are assigned by putting their ID numbers into a list, one time for each day they’ll work that task. As shifts are planned well in advance, the lists for each task will contain up to 99 integers. When a minion is scheduled for the same task too many times, they’ll complain about it until they’re taken off the task completely. Some tasks are worse than others, so the number of scheduled assignments before a minion will refuse to do a task varies depending on the task. You figure you can speed things up by automating the removal of the minions who have been assigned a task too many times before they even get a chance to start complaining.

Write a function called solution(data, n) that takes in a list of less than 100 integers and a number n, and returns that same list but with all of the numbers that occur more than n times removed entirely. The returned list should retain the same ordering as the original list - you don’t want to mix up those carefully-planned shift rotations!

For instance, if data was [5, 10, 15, 10, 7] and n was 1, solution(data, n) would return the list [5, 15, 7] because 10 occurs twice, and thus was removed from the list entirely.

1
2
3
4
solution.solution([1, 2, 3], 0)

solution.solution([1, 2, 2, 3, 3, 3, 4, 5, 5], 1)
1,4

How did I solve the first Google Foobar challenge?

This challenge is a dime a dozen. I know the purpose of this challenge is just to help you to get used to verifying and submitting the solution. 7 days for this challenge is too generous. Feel free to explore and enjoy the new feeling, admiring the beautiful google site you’ve never seen before. LOL

Ok, let’s start cleaning up the tasks for the minions…

resolve level 1 googlefoobar challenge meme

Damn, it failed! fail for what? I don’t know why does it rain fail šŸ¤”

Hmmm, seem it’s not as simple as I thought it would be, I tried looking around, and everyone has the same answer as me but they passed and I failed???

resolve level 1 googlefoobar challenge failed Google Foobar doesn’t tell we what the testcases are. So I tried to steal their testcases by sending the requests to my server with testcases data.

When the solution is run by command verify solution.py, it sends the arguments to my server, So I can check the logs on my server.

Expected logs will look like this: GET /?data=1,2,2,3,3,3,4,5&n=1 resolve level 1 googlefoobar challenge successfully But NO, Google Foobar knew we were going to do it, so they blocked outbound requests already. fail to hack googlefoobar

Stuck in finding a testcases, I don’t know what to do now, just trying to submit again: resolve level 1 google foobar challenge successfully Boom, It passed. What?… I don’t know, Just the same code as before, but it passed. haha

Then I run submit solution.py to submit the solution. That’s all for the first Google Foobar challenge. end part of level 1 google foobar challenge

solution.py:

1
2
3
4
5
6
from collections import Counter


def solution(data, n):
    counted_data = Counter(data)
    return [k for k in data if counted_data[k] <= n]
Made with the laziness šŸ¦„
by a busy guy