### Leetcode #1423: Maximum Points You Can Obtain from Cards

You can’t choose the 2nd element from the front unless you have chosen the first one. Similarly, you can’t choose the 2nd element from the back unless you have chosen the last one already. You want to choose a total of K numbers. There are limited number of ways in which you can choose those numbers given the constraints … … More Leetcode #1423: Maximum Points You Can Obtain from Cards

### Leetcode #1443: Minimum Time to Collect All Apples in a Tree

Whenever you are at a node, say p, you will collect all apples in p’s subtree before returning back to the original root. This will avoid traveling the same path multiple times. …. Because you have the list of edges, construct a better representation – adjacency list – of the tree. … More Leetcode #1443: Minimum Time to Collect All Apples in a Tree

### Leetcode #1472: Design Browser History

Thought Process – Say you visit a website A. Then got to B, C, and D in the order. If you go back, you will be at C. Go back further, you will be at B, and if you go back again, you will reach A.
Thing to note is that the order of websites totally reversed when going back compared to the order in which you visited them. So certainly we need a stack data structure for the back operation which will store the history. … More Leetcode #1472: Design Browser History

### Leetcode #1424: Diagonal Traverse II

In a 2D matrix, elements in the same diagonal have same sum of their indices. So if we have all elements with same sum of their indices together, then it’s just a matter of printing those elements in order. … More Leetcode #1424: Diagonal Traverse II

### Understand each data structure with a real-world example

There are some common data structures used frequently for various applications and hence it becomes important to study them well. This is also a reason why coding interviews focus so much on them. Data structures are the core of your application because they control how efficient your application is. Making a bad choice there is very costly and hence we will see appropriate usage of each data structure with one common theme across the post. … More Understand each data structure with a real-world example

### Intuitively Choose the Right Data Structure

An important thing to note is that in an interview when you are solving a problem, you almost always choose a data structure for its strength. In other words, you don’t usually choose a data structure just because it has fewer weaknesses and has a good average-case performance. For example, if you want to find a maximum number frequently, priority queue/heap is most likely the best choice. If you want to store some value associated with a key, a hashmap is likely the best choice. … More Intuitively Choose the Right Data Structure

### What you should study for a successful interview loop

Any question related to computer science is a fair game in an interview, because believe it or not – you do need knowledge of most of these things for the job when working on a project. Although it’s not feasible to study everything, you can be strategic about the preparation and prioritize one thing over the other depending upon how much time you have for your next interview. … More What you should study for a successful interview loop

### Key to Solving Every Problem in a Coding Interview – Choose the right tool

In a way, this post is a summary of your data structures analysis class. There are mainly 7-8 data structures that are very common in the coding interviews. In reality, there can be an infinite number of data structures because data structures are just a way to store the data and you can create your own ways of storing data. From the point of view of the coding interview, you are going to get tested on standard data structures and hence you should focus on them. Although I will discuss each data structure in detail in separate posts, you can use this post as a time & space complexity cheatsheet, or as a checklist of different data-structures to study for your interview. … More Key to Solving Every Problem in a Coding Interview – Choose the right tool

### Dynamic Programming

The idea behind solving dynamic programming problems is simple – remember what you have already solved and use the already computed solution in case you are solving the same problem again. In other words, solve one problem only once and remember the solution to it so that you can quickly provide the solution without the need to solve the problem again. … More Dynamic Programming

### Backtracking

Recursion makes exploration of all paths/branches of the tree very easy. At any time you only have to think about the current level and recursively call the function for exploring the children. Whenever you have a recursive code, you should always think about the base case where you will terminate the recursion. Depending on the problem it would, of course, differ. For the above example, the terminating condition can be “Is the current node the key?” … More Backtracking