Monthly Archives: September 2019

Leetcode 57: Insert Interval

This was a little bit fiddly with some edge cases to consider. Iterate through the intervals array attempting to insert the new range or merge it. So at every step we need to check if the new range is before … Continue reading

Posted in programming | Tagged , , | Leave a comment

Leetcode 56: Merge Intervals

Key insight is that it is much easier and more efficient to merge if we sort the ranges by the range begin. That results in O(nlogn) solution and I don’t think it can be done quicker than that.

Posted in programming | Tagged , , | Leave a comment

Leetcode 55: Jump Game

The key insight to find the optimal O(n) solution is that we should evaluate our situation at every step as we iterate through the array, trying to maximise our remaining steps available. So in the first whiteboard example [2,3,1,1,4], we … Continue reading

Posted in programming | Tagged , , | Leave a comment

Leetcode 51: N-Queens

The n-queens 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

Posted in programming | Tagged , , | Leave a comment