-
Recent Posts
Recent Comments
Archives
Categories
Meta
Monthly Archives: May 2019
Leetcode 32: Longest Valid Parentheses
Note the following test case “()(()” will trip up a simple counting algorithm, which was my first attempt. So I then used a stack to keep track of outstanding open bracket positions. When they are matched with a close bracket, … Continue reading
Leetcode 31: Next permutation
A few observations need to be made to solve this problem efficiently. The best way to make those observations is to write out a bunch of sequences (I used most of 1,2,3,4). Notice that we need to look for a … Continue reading
Leetcode 25: Reverse nodes in k-group
This problem is similar to reverse a linked list but we wrap that in a loop so we do it repeatedly while there are k nodes ahead. We also need to wire the previous k sequence end with the the … Continue reading
Leetcode 23: Merge k sorted lists
Here are my whiteboard notes for solving this problem: And here is my c++ source code for the solution: https://gist.github.com/adamkorg/fb698c0785845576ff0b42a091547691 Initially I started off with what I thought was a simple inefficient way of finding the next smallest node but … Continue reading
Leetcode 17: Phone key combinations
Use recursion to walk through the combination space. I use an array of codes, which maps the index to the letter combinations for that index. In the recursive function we loop through all the possible letters for the current number … Continue reading