Programmer Career, or Cracking Coding Interview

For an IT-related book, this book has an absolutely unbelievable rating on Amazon’s website (as of September 6th this is # 388 in the general rating of books and No. 1 for the Computers & Technology section), therefore, as a curator of this project, I was just happy, when Peter received exclusive rights to publish this best-selling book in Russia.
A little bit about the author of the book. Gail Luckman is cuteAmerican IT-girl, who, however, during the preparation of the Russian edition managed to get married and acquire a second name McDowell. Gail interviewed applicants at Google, Microsoft and Apple for several years, and then founded her own company CareerCup, which helps programmers prepare for an interview at major IT companies. And, of course, Gale is also famous as the author of the book Cracking Coding Interview, which has been reprinted in the West for many years and has not left the top lines of the bestseller book charts. Gail Luckman also speaks about enterprise by the fact that she personally acts as the publisher of her own books and we even negotiated directly with her about licensing books in Russia (in general, it’s nonsense for the modern publishing business).
What is this book about?
The name may give the impression that it is dedicated to describing the interview process and hiring in large corporations: how to dress, how to behave, what is the practice of conducting interviews on Google or Microsoft, and how objectionable job seekers in each company are denied. Not really.
By the way, an interesting story: our colleagues from the Ozon online store were also embarrassed by the title of the book, and they put it in the section “Personnel Accounting and Paperwork”, and it took us some effort to return the publication to the correct classifier branch .
So, Cracking Coding Interview should be put on a par with classic books on algorithms that make programmers think and improve. The above topics really do have a little space (namely, 50 pages), but the main and most valuable part of the book is almost 400 pages of real questions and test items that applicants receive during interviews at the most famous IT companies in the world. Of course, this book will help you if you are really going to an interview on Google, but in itself it will give any programmer the opportunity to take a fresh look at his skills and his development as a professional, offering not only abstract, but also very real tasks and solutions that can be used in practice.
In total, the book contains 150 tasks (and the correct answers to them!) On topics such as OOP, testing, recursion, trees and graphs, databases, flows and probability theory, etc. You can see the similar contents of the book at this link (PDF-file on the publisher’s website).
And as a seed, we suggest that you try to complete one of the test tasks from the book from the section "Tasks of increased complexity"
Task
Write a method that generates a random sequence of m integers from an array of size n. All elements are selected with the same probability.
The answer from the book will be published in the comments tomorrow, September 7, at 18:00. The request to the owners of the book not to give clues.
And below, as an example, we give another task, from the section "Recursion and Dynamic Programming" with the correct answer.
The task.
Implement the paint fill feature that is used by many image editors. Given a plane (two-dimensional array of colors), a point and a color that you need to fill the entire surrounding space, painted in a different color.
Solution
First of all, let's visualize the method. When we call paintFill (“press” the fill button in a graphical editor), being, for example, on a green pixel, we want to expand the boundaries. We move further and further by calling paintFill for the surrounding pixels. If the color of the pixel is different from green, we stop.
You can implement this algorithm recursively:
1 enum Color {
2 Black, White, Red, Yellow, Green
3}
4
5 boolean paintFill (Color [] [] screen, int x, int y, Color ocolor,
6 Color ncolor) {
7 if (x <0 || x> = screen [0] .length ||
8 y <0 || y> = screen.length) {
9 return false;
10}
11 if (screen [y] [x] == ocolor) {
12 screen [y] [x] = ncolor;
13 paintFill (screen, x - 1, y, ocolor, ncolor); // left
14 paintFill (screen, x + 1, y, ocolor, ncolor); // right
15 paintFill (screen, x, y - 1, ocolor, ncolor); // top
16 paintFill (screen, x, y + 1, ocolor, ncolor); // bottom
17}
18 return true;
19}
20
21 boolean paintFill (Color [] [] screen, int x, int y, Color ncolor) {
22 return paintFill (screen, x, y, screen [y] [x], ncolor);
23}
Pay attention to the order of x and y in the screen [y] [x] array and remember that when you solve the problem associated with computer graphics, you need to use this order. Since x corresponds to the horizontal direction, this variable describes the column number, not the row number. The value y corresponds to the line number. It is very easy to make a mistake in this place, both during the interview and during daily programming.
- Book on the publisher’s website
- Book on Ozon