Jekyll2024-01-24T16:00:41+00:00https://gukov.dev/feed.xmlgukov@’s blogThoughts on software engineering, maths and life.Pro Bono Interview Training2020-08-10T17:00:00+00:002020-08-10T17:00:00+00:00https://gukov.dev/interview/training/2020/08/10/pro-bono-interview-training<p>Hey there. I can help you prepare for a technical interview - <strong>for free</strong>!</p>
<p>I want to start conducting mock interviews, i.e. give a technical exercise for 45-60 minutes,
share feedback, and, if appropriate, give advice for improvement.
Drop me a line at <a href="mailto:contact@gukov.dev">contact@gukov.dev</a>, and we’ll find out if I can help.
My bandwidth is limited, but I’ll reserve for it a few hours a week.</p>
<p>This idea has been on my mind for a while.</p>
<p>I kinda know how the interviews work. I did a few dozens, both as an interviewer and a candidate.
Also, I was trained as an interviewer at Yandex and at Google. I rarely conducted <em>mock</em> interviews
though, so this experiment is a learning opportunity for me too.</p>
<p>My motivation is that often people flunk their interviews simply because they’re not
experienced with the process. Interviewing is a skill too, and if you don’t have it, you’ll
have a harder time getting a job (even if you’re a superstar engineer). And if I can help you
overcome this barrier and land a job at your dream company, it’s totally worth an hour or two of my time.</p>
<p>P.S. I’m most comfortable conducting the interviews in coding (esp. algorithms) and system design (also NALSD).</p>Hey there. I can help you prepare for a technical interview - for free!Jane Street puzzle: Circle Time!2020-07-18T15:00:00+00:002020-07-18T15:00:00+00:00https://gukov.dev/jane/street/puzzles/2020/07/18/jane-street-circle-time<p>Every month Jane Street, a quantitative trading firm, posts a math puzzle on their website.
How cool is that?</p>
<p>In June, they posted a
<a href="https://www.janestreet.com/puzzles/circle-time/">Circle Time</a>
puzzle which I found quite fun to solve. This is this kind of a puzzle which looks easy at first,
hard when you start working at it, and easy again when you finally find the solution.</p>
<p>There are two solutions available online: a
<a href="https://medium.com/@dhrumilp15/jane-street-june-20-circle-time-107876577b09">closed form solution</a>
that uses analytic geometry and an
<a href="https://willemhoek.com/b/Solving-Jane-Street-Puzzle-June-2020">approximate solution</a>.
The former is really heavyweight, and the latter feels like cheating to me :)</p>
<p>Actually, this puzzle doesn’t require anything other than the <strong><em>middle-school math</em></strong> to solve!</p>
<p>Let’s get to it. The puzzle goes as follows:</p>
<blockquote>
<p>Call a “ring” of circles a collection of six circles of equal radius, say r, whose centers lie on
the six vertices of a regular hexagon with side length 2r. This makes each circle tangent to its
two neighbors, and we can call the center of the regular hexagon the “center” of the ring of
circles. If we are given a circle C, what is the maximum proportion of the area of that circle
we can cover with rings of circles entirely contained within C that all are mutually disjoint
and share the same center?</p>
</blockquote>
<p>Let me visualize it for you. The “ring” inscribed in a circle looks like this:</p>
<div id="drawing1"></div>
<p>Now we want to stuff the circle with the “rings” so that they don’t overlap and cover the
maximum possible area. It’s fairly easy to prove that the optimal coverage looks like this:</p>
<div id="drawing2"></div>
<p>Indeed, if there was another optimal coverage where two consecutive rings weren’t inscribed
as tightly as here, whey would touch each other in 0 or 6 points instead of 12. In case of
6 touching points you could rotate the inner ring a little so that it doesn’t touch
the outer ring at all. Then you could upscale it (and all rings inside it) until it touches the
outer ring again. This little manipulation would yield a new valid coverage of a bigger area,
which means this coverage was not optimal.</p>
<p>Notice that the optimal coverage is infinitely self-similar. Every ring is inscribed in another ring
in exactly the same fashion. This means, every ring’s area is $X$ times smaller than the previous one.
Their areas form a geometric series, and the total area is the sum of this series. If the area of the
outermost ring is $A$, <a href="https://en.wikipedia.org/wiki/Geometric_series#Formula">the sum</a>
is $\frac{A}{1 - X}$.</p>
<p>Let the radius of the large circle be 1.
It doesn’t affect the result in any way but will make the calculations more brief.</p>
<p>Now the area of the outermost ring is easy to find. Every circle in this ring has a radius 3 times
less than the radius of the big circle - $\large \frac{1}{3}$. This means, area of the ring is
$6 * \pi * (\frac{1}{3})^2 = \frac{2}{3}\pi$. The area of the big circle is just $\pi$.</p>
<p>The answer to the problem simplifies to $\large \frac{\frac{2}{3}\pi}{1-X} / \pi = \frac{2}{3(1-X)}$.
If we knew $X$, we would know the answer.</p>
<hr />
<p>So, what is the value of $X$?</p>
<p>Remember how $X$ is a relation of the areas of 2 consecutive rings? Let’s say the inner ring is
built of the circles of radius $r$, and the outer ring - of radius $R$. Then $X = \large (\frac{r}{R})^2$,
because <a href="https://en.wikipedia.org/wiki/Square%E2%80%93cube_law">areas relate as squares of lengths</a>.</p>
<p>Finding $\large \frac{r}{R}$ is the cornerstone of this puzzle.
And all you need for it is… the Pythagorean theorem!</p>
<p>Look at the top-right quadrant of the picture.</p>
<div id="drawing3"></div>
<p>Notice 3 things here:</p>
<ol>
<li>
<ul>
<li>$DE = EB = AB = r$;</li>
<li>$BC = r + R$;</li>
<li>$OC = 1 - R = \frac{2}{3}$.
<br /><br /></li>
</ul>
</li>
<li>
<p>$\bigtriangleup OBD$ is equilateral because it’s $\frac{1}{6}$ of a hexagon on a bigger picture.
We already know that its side $DB = 2r$.</p>
<p>This means, its height $OE = \sqrt{3}r$.</p>
</li>
<li>
<p>$\bigtriangleup OAB = \bigtriangleup OEB$ because they have identical 2 sides and an angle.</p>
<p>This means, $OA = OE = \sqrt{3}r$. In turn, $AC = OC - OA = \frac{2}{3} - \sqrt{3}r$
<br /><br /></p>
</li>
</ol>
<p>Voila, we know all sides of $\bigtriangleup ABC$. Now apply the Pythagorean theorem and get the answer:</p>
<p>$r^2 + (R - \sqrt{3}r)^2 = (r + R)^2$</p>
<p>$3r^2 + 3R^2 - (4\sqrt{3} + 2)rR = 0$</p>
<p>$3(\frac{r}{R})^2 - (4\sqrt{3} + 2)\frac{r}{R} + 3 = 0$</p>
<p>$\Large{\frac{r}{R} = \frac{2\sqrt{3} + 1}{3} \pm \frac{2\sqrt{1+\sqrt{3}}}{3}}$</p>
<p>Our quadratic equation has 2 roots. One of them is $\large\frac{r}{R}$ (the one that’s less than $1$), and the other,
interestingly enough, is $\large\frac{R}{r}$!</p>
<hr />
<p>Te rest is simple. We already know that the answer is $\large \frac{2}{3(1-X)}$, $\large X = (\frac{r}{R})^2$ and
$\large \frac{r}{R} = \frac{2\sqrt{3} + 1}{3} - \frac{2\sqrt{1+\sqrt{3}}}{3}$.</p>
<p>Combined, this gives us:</p>
<p>$\Large \frac{2}{3(1-(\frac{2\sqrt{3} + 1}{3} - \frac{2\sqrt{1+\sqrt{3}}}{3})^2)} =$</p>
<p>$\Large = \frac{1.5}{\sqrt{25 + 17 \sqrt{3}} - 2 \sqrt{3} - 2} \approx 0.783464$</p>Every month Jane Street, a quantitative trading firm, posts a math puzzle on their website. How cool is that?