

Longest substring with ‘K’ distinct characters (medium).Maximum sum subarray of size ‘K’ (easy).You’re asked to find the longest/shortest substring, subarray, or a desired valueĬommon problems you use the sliding window pattern with:.The problem input is a linear data structure such as a linked list, array, or string.In some cases, the window size remains constant and in other cases the sizes grows or shrinks.įollowing are some ways you can identify that the given problem might require a sliding window: The Sliding Window pattern is used to perform a required operation on a specific window size of a given array or linked list, such as finding the longest subarray containing all 1s. Sliding Windows start from the 1st element and keep shifting right by one element and adjust the length of the window according to the problem that you are solving. If you haven’t, check out these refresher courses on Data Structures. The following patterns assume that you’ve brushed up on Data Structures. This just touches the surface - I strongly recommend checking out Grokking the Coding Interview: Patterns for Coding Questions for comprehensive explanations, examples, and coding practice. Here, I’ve laid out the top 14 patterns that can be used to solve any coding interview question, as well as how to identify each pattern, and some example questions for each.


That’s why I try to focus on helping developers grasp the underlying patterns behind each question - so they don’t have to worry about solving hundreds of problems and suffer from Leetcode fatigue. If you understand the generic patterns, you can use them as a template to solve a myriad of other problems with slight variations. One of the most common points of anxiety developers that I’ve talked to have before the interview is: Have I solved enough practice questions? Could I have done more? One of the outcomes of this is that it’s now common for developers to spend weeks combing through hundreds of interview questions on sites like LeetCode. There’s so much material to cover, and often much of it feels irrelevant to what devs are doing in their day jobs, which only adds to the stress. The process of preparing for coding interviews is anxiety-inducing for many developers.
