Category Archives: programming

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

Posted in programming | Tagged , , | Leave a comment

SudokuSolverX Android app

I’ve created a Sudoku puzzle solving app. See details here:

Posted in programming | Tagged | Leave a comment

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

Posted in programming | Tagged , , | Leave a comment

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

Posted in programming | Tagged , , | Leave a comment

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/leetcode-31-next-permutation/ I thought I would have … Continue reading

Posted in programming | Tagged , , | Leave a comment

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

Posted in programming | Tagged , | Leave a comment

Leetcode 44: Wildcard Matching

There were some tricky test cases in this problem that meant my original recursive solution was too slow. My second attempt was inspired by this post:http://yucoding.blogspot.com/2013/02/leetcode-question-123-wildcard-matching.html The solution basically steps through matches and then if it finds a * wildcard … Continue reading

Posted in programming | Tagged , , | Leave a comment

Leetcode 43: Multiply Strings

The general steps to do long multiplication are fairly straightforward but the implementation was a bit fiddly. I think it would be easier to to reverse the strings and work on them in reverse, then the least significant index will … Continue reading

Posted in programming | Tagged , , | Leave a comment

Leetcode 42: Trapping Rain Water

This is a tricky leetcode problem. There are a few observations that need to be made. Water traps between two bars and only fills each of those gaps to a volume that is the gap’s height taken away from the … Continue reading

Posted in programming | Tagged , , | Leave a comment

Leetcode 41: First Missing Positive

This is tricky and probably not typical of a real world problem, so I don’t know how useful it is know. Given the criteria of running it O(n) time and only using constant extra space, the only way we can … Continue reading

Posted in programming | Tagged , , | Leave a comment