Symmetric Tree

Leetcode considers this question to be easy, but it was a bit more complicated than that at first for me. Letโ€™s try solving it three different ways: Whenever I can, I always try to do BFS. It seems much more natural. BFS - 1st solution func isSymmetricBFS(_ root: TreeNode?) -> Bool { var queue: [TreeNode?] = [] queue.append(root) while !queue.isEmpty { let temp = queue queue.removeAll() // ๐Ÿ”‘ to make sure you don't expand on `nil` nodesย โ€”ย otherwise it would be endless for node in temp where node !...

January 12, 2025 ยท 2 min

The effect of direction on recursion and understanding code - Longest Common Subsequence

Today Iโ€™m going to discuss another fun and common challenge. Itโ€™s the Longest Common Subsequence a.k.a. LCS. Iโ€™ll first focus on discussing a pain point I went through when I was trying to compare the algorithm I deduced on my own vs a few other algorithms I saw online. Our algorithms seemed very similar. Yet different. It made debugging my code based on other code very difficult. This is a very common problem I face when I doing leetcode....

December 2, 2023 ยท 8 min