Skip to content

puzzles

2 posts with the tag ā€œpuzzlesā€

Solved all React challenges on Hackerrank and not satisfied

I read that hakerrank has challenges organized by domain — for example, the React domain — and decided to solve them as part of my interview preparation.

I completed all of them, but not satisfied. Here’s why:

  1. The challenges don’t feel like real interviews. They give you a lot of code, while in actual interviews you often write components almost from scratch.
  2. The tests are not reliable. In one case, I had to remove the key from react element just to make their test pass. Test kept a reference to the element at the start and didn’t update it after re-render. In another challenge, tests used hardcoded outdated dates, so I had to add a weird condition just to pass.
  3. The platform itself has issues. Sometimes my progress wasn’t saved. A couple of times I submitted a solution, saw the ā€œCongratulationsā€ screen, went back to the challenge list — and it showed the challenge as unsolved. I had to redo the solution. Eventually, I started double-clicking the submit button just in case, because I didn’t want to retype everything again.

Overall, I regret the time spent a little, because mostly I fought with tests, not with solving problem. Moreover, challenges turned out to be not so interesting. I liked leetcode experience more.

Hakerrank page with completed challenges

Boxes in boxes, Or what occupied my mind lately

I sometimes solve puzzles on Codewars and LeetCode, and recently, I came across a kata called ā€œBoxes in boxesā€.

It’s not a particularly difficult problem, but I struggled with it. My first issue with puzzles like this is that I’m not great at spatial reasoning. Because of this, I couldn’t immediately understand the pattern for drawing the boxes.

The second problem was that even after I figured out the pattern, I couldn’t implement it. In my mind, I thought I needed to redraw the boxes I had already calculated. So, in my understanding I need to start by drawing one box and then try to add the lines for two boxes, and repeat already drawn boxes. But I just couldn’t wrap my head around it.

Eventually, I was forced to check other solutions (after obsessing over it for two evenings without making any progress). And guess what? I still didn’t get it. I mean, I could look at the solution, understand the code, and see what it was doing, but I just couldn’t grasp how it produced the final result.

In the end, I wrote my own solution based on the ideas from another one I found, but I needed to debug it carefully to fully grasp the concept.

I’m leaving code with my comments here as a reminder of the solution and my understanding.

function draw(n) {
// all for one box, our start
let res = [" _ ", "|_|"];
for (let i = 1; i < n; i++) {
res = [
// top line - just add tops of boxes
' _' + res[0],
// draw existing boxes without left border (top 1/2 part is repeat existing but partially)
...res.slice(1).map(str => '| ' + str.slice(1)),
// draw existing with left border and without bottom
...res.slice(1, -1).map(str => '| ' + str),
// draw bottom
'|_' + res[res.length-1],
]
}
return res.join('\n');
}

I hope it will never be asked on interview 🤪