Code Katas
If you take one piece of advice from this site, this is it.
Code katas are how I spend the majority of my time when I prepare for coding interviews. I also use them to warmup before interviews to calm myself down and get into the right mental space.
They are the equivalent of easy hackerrank/leetcode problems.
Category | Katas |
---|---|
Arrays/Strings | Quicksort (hackerrank) Remove adjacent duplicates (hackerrank) Find array index with equal sums (hackerrank) |
Linked Lists | Compare two linked lists (hackerrank) Reverse a linked list (hackerrank) |
Trees | In-order traversal (hackerrank) Pre-order traversal (hackerrank) Post-order traversal (hackerrank) |
Graphs | Depth-first search: Connected cells in a grid (hackerrank) Breadth-first search: Shortest reach (hackerrank) |
Dynamic Programming | Ways to climb a staircase (hackerrank) |
How to use code katas
For every kata, do the following:
- Practice until you can code the solution in under a minute. No backtracking, no hesitation, no mistakes.
- Think about the time/space complexity as you code. Think about this with every line you write. When allocating supplemental data structures, think about how this impacts space complexity. When you add a for loop, think about what this means for time complexity.
All it takes is regular practice. You don’t need to grind for hours, you just need to do a little bit regularly until you are able to just sit down and confidently code the solution without backtracking or hesitation. Even 5 minutes of practice a day on one of these is beneficial.
What are code katas?
The concept borrows from martial arts where students will perform a pre-defined series of movements called katas in order to perfect techniques and build muscle memory.
Code katas have the same goal of perfecting coding and problem solving techniques and building muscle memory for them.
They help you build up a coding toolkit that you can use fluently even during high pressure situations like interviews.
Once you recognize that a problem requires a breadth-first-search or an array traversal, you can spend minimal time and effort on coding it up. The faster you can write the code, the more time you have to test it for bugs or optimize it.
Code katas address the most common mistake I see candidates make – spending all their time figuring out how to write a tree search or array traversal and not having enough time to optimize or find bugs or even to finish.
This is unfortunate because it’s unnecessary. This is the easiest part of the coding interview to perfect.
The hard part of a coding interview should be determining which data structure and algorithm to use. Implementing your solution should be the easy part.