
Hello, dear readers of Habrahabr!
In this article I will talk about how I, an unremarkable student, managed to knock out an interview in one of the companies of the Biggies list, Facebook, without any particular problems.
Immediately to the point: solving a
school level problem on a
githaba . I stuck the thematic face, did everything in the Objective-C tradition, should compile on poppies. I hope this reading will open the eyes of many Russian students, how easy it is to get into the big companies of your dreams.
')
Unfortunately, FB is not my priority goal; so I'll go to the interview, look at the questions and write the following article about what was asked and what can I ask at the interview in my studio.
Interested please under the cat.
I will warn you in advance: I do not divide the text into parts, because, it seems, it will turn out small; the whole background and decision took me no more than two hours. Please do not need to prepare yourself for something supernatural - I suspect that this task is given in Russian school programming circles.
It was Tuesday, I had nothing to do after university, I ran into a Facebook lecture on campus for free pizza. By the way, I ate three slices, however, the most delicious pizza, in my memory, was at the Electronic Arts presentation. The guys from Zuckerberg filled a full hall of students, about 150 people. We talked about the application process in the FB, about the interview series and decided a couple of simple tasks like “Implement the search for duplicates in the array” - tasks of the kindergarten level to think for 30-40 seconds.
I was about to leave - the pizza was over, and I was getting very bored. Moreover, I managed to get tired of everything - I raised my hand before everyone else and always offered a better solution. In the middle of the lecture, I generally stopped asking and paying attention to me, which definitely upset me greatly. However, in the end, they gave us a “task for the house”, and the main recruiter said to throw him a solution by email if it suddenly appears.
I was very surprised: it was necessary to write a function that would accept a number (the side of a square) and produce a spiraling sequence of numbers. An example for the side of the square equal to nine is presented below:

At first, I forgot about this puzzle, but I rewrote it on a poster that I was given for answers. And others were handing out T-shirts - well, what is it for me? For being a lot of answers.
I got bored on the bus on the way home (it's hard to endure for 10 minutes), so I put on an approximate algorithm on the same poster. When I arrived home, I drank a couple of power engineers in order to keep my mind sharp for another couple of hours, and started writing code in Objective-C. Because I do not know pluses at a sufficient level. Because I'm such a bummer.
In a hurry, I threw in the program interface and made it a little thematic - what if a recruiter came up with a hundred solutions, and they were all the same? Here you need to somehow stand out from the crowd!

Well, that doesn't matter. The basis of the matrix, I took a two-dimensional array. In my case, NSArray from NSArray from NSNumber. And immediately wrote a method for outputting this array in the right window. The window was WebView - you can conveniently build a HTML table in it:
Caution code! - (void)printResult:(NSArray *)result {
It remains only to fill the array with data. Scan your eyes on the method code, and below I will highlight some points.
Caution code! - (NSArray *)getNumbersArrayForSide:(int)side {
- I decided to create a matrix of the right size, filled with NSNull objects; and then fill it with the necessary numbers.
- Each iteration of the side of the square is reduced by 2, because we cut one number from two sides.
- The offset is the coordinate of the beginning of the current square (both "x" and "y" are the same).
- Each square first draws the top, then the right side, then the bottom, then the left side.
- If the side of the square is 1, you do not need to draw the bottom; otherwise, the center number will be 1 more. Why? And here's your homework :)
Here is the result for the side of the square equal to eight:

Having successfully completed coding and testing, I sent an email with my resume and decision to the email of the main recruiter. Tonight I found the answer: I was thanked and invited to an interview at the office.
Honestly, I was stunned. Surely, people sent better solutions: why me? It turned out, everything is simple. From a telephone conversation, I realized that out of 150 people in the lecture, only three sent the solution (I am among them). One solution did not compile, another had a simple console solution on the pros, and I have such a nice UI. Looks like the choice was obvious.
Very often I hear students complaining that they are not called back after sending a resume to the company. I remember a joke about God and a lottery ticket.
Thank you for reading to the end! So, by solving a school-level task, I managed to get an interview on Facebook. I am sure that there is a simpler solution, and I really want to know about it! Please share your solution in the comments.
By tradition, I ask to report about all found errors and
typographical errors in
my habracenter .