Connect with us

Articles

How I build a habit to leetcode

I’ve always wanted to work on my interviewing skillsets so that when the opportunity to interview arises, I’ll be ready for the interview. My efforts to incorporate Leetcode as a daily route was sporadic over the last few years.

Coding interviews require a different set of skillset compared to practical software engineering. Interviews mainly test on algorithms and data structures, which most software developers do not come across in their day-day work.

I’ve always wanted to work on my interviewing skillsets so that when the opportunity to interview arises, I’ll be ready for the interview. My efforts to incorporate Leetcode as a daily route was sporadic over the last few years.

There will be times when I get really motivated and managed to leetcode almost daily but eventually when life comes knocking back, the routine started to wane off.

Since December last year, I had another surge of motivation to leetcode. But this time round, I was ready, prepared and equipped with the several habit tips from the book “Atomic Habits” by James Clear.

The 4 tips are:

Make it obvious

The 2 most common habit cues are time and location. Habit stacking is a strategy you can use to pair a new habit with a current habit.

The habit stacking formula: After [CURRENT HABIT], I will [NEW HABIT].

I stacked the habit of leetcode with my gym routine.

Before going to the gym, I will head to the coffeeshop to leetcode.

Make it attractive

Habits are a dopamine-driven feedback loop. When dopamine rises, so does our motivation to act. It is the anticipation of a reward not the fulfilment of it that gets us to take action.

Temptation bundling is one way to make your habits more attractive. The strategy is to pair an action you want to do with an action you need to do.
Habit Stacking + temptation bundling formula: Before [CURRENT HABIT — something that I desire ], I will [HABIT I NEED]

This is rather similar to mentioned in rule 1.

Before going to the gym (something that I want), I will head to the coffeeshop to leetcode.

Make it easy

It is human nature to follow the Law of Least Effort, we will naturally gravitate toward the option that requires the least amount of work.

For a habit, in the beginning, when you’re motivated and excited, you can muster the strength to get started. But after a few days, such a massive effort feels exhausting. The less energy a habit requires, the more likely it is to occur.

Start with the questions that are easiest and have solutions.

I sort questions in my queue in this order.

  • Solutions provided
  • Difficulty
  • Acceptance rate (the % of submissions that are accepted.)

Make it satisfying

The human brain evolved to prioritise immediate rewards over delayed rewards. To get a habit to stick you need to feel immediately successful — even if it’s in a small way.

Habit tracking: simple way to measure whether you did a habit. Habit tracking makes act of performing your act attractive. Tracking can become its own form of reward. It is satisfying to cross an item off your to-do list.

I kept a to-do list and a habit tracker on my calendar of my progress on Leetcode and other habits that I’m trying to build.

Calendar Habit Tracker. 2LC (2 Leetcode), 2 SD (2 System Design)

Calendar Habit Tracker. 2LC (2 Leetcode), 2 SD (2 System Design)

My results so far are that

  • completed close to 200 questions on Leetcode.
  • participated in one Leetcode live contest
  • learnt numerous data structures such as
    • adjacency list
    • monotonic stack / queue
    • heap / priority queue
  • learnt numerous algorithms
    • Dijkstra
    • Disjoint Set Union
    • DFS / BFS iterative and recursive
    • Deterministic State Automaton
    • Topological Sort

Thank you for reading till this far, I hope that you managed to learn something from this article and incorporate it in your life.

Full Article: Yew Wee @ Medium

Advertisement

Trending