Home > Reflections | ⏮️ ⏭️

# 2024-06-09

## ☕ Motivation

## 🏋 Practice

Today I want to try a new planning strategy.

The plan is to

- Paraphrase the question
- Consider any clarifying questions
- Identify the primary algorithm or technique that will drive my solution

- This primary algorithm or technique should
- be recognizable to another engineer (e.g. an interviewer)
- support runtime complexity analysis

- Write down the expected run-time complexity
- Stop planning and move on to coding

The goal is to dramatically speed up my planning process.

If I’m aiming to solve a problem in 15 minutes, I should aim to be done planning in 2 minutes.

### The Problem

974. Subarray Sums Divisible by K

Given an integer array

`nums`

and an integer`k`

, returnthe number of non-emptysubarraysthat have a sum divisible by`k`

.

Asubarrayis acontiguouspart of an array.

### 🪞 Reflections

- It’s frustrating to not find the optimal solution, but I think I did the right thing during planning. I observed that this was an O(N^2) algorithm, it probably wouldn’t be fast enough, but I couldn’t come up with a better solution in a reasonable amount of time. This is the best I can do in this scenario during an interview.
- I forgot to check the clock after planning, so I’m not sure if I hit my 2 minute mark or not. I suspect probably not, as it took a bit of time to think of a solution.
- But - getting a working (though not fast enough) solution in under 19 minutes is still pretty good.
- I’m not sure if this is a good sign or a bad sign, but even after reading through the optimal solution a few times, I find it nearly incomprehensible. Either this is a new trick I need to learn or it’s obscure and hopefully not critical to understand.

### My Solutions

## 🏋️ Another Mock Interview!

A friend offered to give me a mock interview today.

This was a great session and I got some good feedback.

After our session, I wrote up a couple of solutions to the problem in a git repo.

### 🪞 Reflections

- Overall, the session went pretty well.
- I did get bogged down managing state during code implementation, which is an area to continue to focus on improving.
- I think he had a great tip for me here.
**When struggling to get the details right, it can be helpful to write out an example input (in a comment) and manually work through the algorithm.**After writing it out, it should be easier to reference in code. I’ll need to practice this. - Whoops, I implemented a small helper function before the main function. He mentioned that I should avoid that, and I’d already come to this conclusion previously.
- Time management.

- Don’t implement helper functions unless the interviewer asks for them.
- He said I did a great job of communicating and narrating my thought process, but I can afford to be less verbose. It’s okay to mention that I need to think for a bit, silently mull over the problem for 15 seconds, then continue on with my conclusions.
- It’s best to not have to change approaches mid problem.