Let’s say, we have a problem that requires us to print all the digits of a number from the left to right. A simple approach would be extracting the digits from the right to the left, storing them in…
In the previous article, we learned about Bitboard and how to use it in a simple board game. In this article, let’s see how Bitboard can be actually used to implement a chessboard. For those who are…
Sometimes, you will need to count the frequency of letters in a string and do something with that count. For example, with a simple algorithm to check if a string is a permutation of another one, we…
Cyclic Sort is an easy to implement and efficient algorithm. The only caveat is that it requires an input array to be a continuous range of values. It can be applied to the problems of finding…
In a Linked List, traversal is restricted to forward only, you can’t really go back to previous nodes once you go past them. When working on a problem that requires us to do some lookup in a Linked…
For the problems that require us to do something a stream of values, or a subsequence of an array, the typical approach is to use a sliding window. A naive way to implement a sliding window is to have…
The problem Given two non-decreasing arrays a of length m, and b of length n. Merge the two arrays into array a. Since it’s an in-place merge, a has some extra spaces to fit the result. The solution…
Due to rounding errors, most floating-point numbers cannot be represented precisely in the computer. This led to some weird situations like: Different languages handle this calculation differently…
When solving palindrome problems, we need to avoid sliding window solution (a.k.a brute force), where we try to generate every substring and check to find the palindrome. The good approach to go for…
The array x is to keep track of all possible integers we can find, the array t is to keep the sum t[i] of every x number from x[1] to x[i]. Now, let’s write a Generator algorithm with Backtracking…
The algorithm is simple: Find the right most element less than n Increase it Set the other right the same It can be implemented as following: And here’s how we would use it: