Tree Basics and some Swift helpers for leetcode

I do leetcoding every once a while, but keep forgetting some tree basics. This post here it to help with that. Types of Tree Trees can have multiple children. Or on the special case of binary trees have only two. A binary tree is still different from a binary search tree (BST) where things follow a certain order. Binary search tree For a Binary tree to be a BST, it has to follow the following rules:...

September 11, 2023 Β· 7 min

The power and expressiveness of Swift ranges

Ranges in swift are super simple to create. Yet they come in various forms. let r1 = 1...3 let r2 = 1..<3 let r3 = ...3 let r4 = 3... let r5 = ..<3 Now they all have range like characteristics, but have slightly different traits. It’s because they’re actually different types. Different Range Types let r1 = 1...3 // ClosedRange<Int> let r2 = 1..<3 // Range<Int> let r3 = ....

March 10, 2023 Β· 6 min

Check if Two Strings Are One Edit Away

Question You can edit a string in three different ways: insert, remove or replace a character. Write a function to see if two strings are one or zero edits away. Example like, like --> true (zero edits) like, likes --> true (one edit: remove/insert) like, life --> true (one edit, replace) like, lik --> true (one edit: remove/insert) like, pine --> false (two edits) like, lion --> false (two edits) Strategy For most questions that require you to return true or false, you can reduce the scope of the question by removing noise....

June 15, 2022 Β· 3 min