Monthly Archives: May 2019

Leetcode 32: Longest Valid Parentheses

This was probably the easiest leetcode “hard” question that I’ve done so far. My first attempt worked on the two examples in the description but failed on the following test case “()(()”. My first attempt just used counters and did … Continue reading

Posted in programming | Tagged , , | Leave a comment

Leetcode 31: Next permutation

Here are my whiteboard notes for solving this: So it turns out this algorithm was first discovered a long time ago. According to Knuth (in The Art Of Computer Programming 7.2.1.2), it goes back to the 18th century. This is … Continue reading

Posted in programming | Tagged , , | 1 Comment

Leetcode 25: Reverse nodes in k-group

My first thoughts for reversing the group was to have start and end pointers, switching those and then moving pointers one step inwards. This is logically how I would tackle reversing array elements but it does not work well with … Continue reading

Posted in programming | Tagged , , | Leave a comment

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

Posted in programming | Tagged , , | Leave a comment

Leetcode 17: Phone key combinations

Recursion is a very natural fit for this problem. Iterate through each letter of each digit and recursively go into each of those letters to the next digit. If we are at the last digit then we add the current … Continue reading

Posted in programming | Tagged , , | Leave a comment