
Recent Posts
Recent Comments
Archives
Categories
Meta
Tag Archives: coding
Leetcode 51: NQueens
The nqueens problem is about arranging n queens on an n x n chessboard such that no queen attacks another queen. It turns out that this is quite a common example for using a backtracking algorithm. However my initial solution … Continue reading
Structured bindings in C++17
Structured bindings are a useful new feature in c++17. They are particularly handy where you have multiple return values. Here are some examples showing how things have evolved over different versions of c++:
Logic gates
Here are some basic logic gates and how we can combine them to get an XOR: In order to perform addition of arbitrary length binary numbers we first start with creating a Half Adder, which can add two single binary … Continue reading
C++ Lambda Expressions
Here are some whiteboard notes I created on c++ lambda expressions. I should create a digital/html version of this reference.
Leetcode 50: Pow(x, n)
A few fiddly cases of exponentiation to deal with in this problem. A simple O(n) solution is fairly straightforward but that will not pass some of the leetcode test cases. An implementation that uses binary exponentiation will work in O(log … Continue reading
SudokuSolverX Android app
I’ve created a Sudoku puzzle solving app. See details here:
Leetcode 49: Group Anagrams
The most efficient way I could think of to solve this problem was to use an unordered_multimap to store sorted strings as keys and the original strings as values. This will then automatically provide the groupings we need. Here are … Continue reading
Leetcode 48: Rotate Image
The idea with my solution is that you work your way through layers of the box, starting with the outside layer and then moving inwards. For each layer we step through four points at a time, starting at the corners … Continue reading
Leetcode 46: Permutations
The obvious way to solve this is to repeatedly call next_permutation() from the standard library. Another way to solve it is to implement what next_permutation() does and I have done that in a previous solution:https://www.adamk.org/leetcode31nextpermutation/ I thought I would have … Continue reading
Origins of the C++ name
In Stroustrup’s “A Tour of C++”, it says that C++ takes its name from: The increment operator (++) combined with C programming language name. George Orwell’s novel “1984”. The first was obvious and expected but the second was surprising, so … Continue reading