Part 1 - State Drive Nagiation: Overview

Intro What triggered the writing of this post were two things: 1. Prior Experience with State Machine We’ve been using state machine for the past few years to simplify a complex onboarding flow. The complexity of our feature rises from: having too many conditions that determine the correct state having the conditions scattered. Some conditions are known at the time of app launch, some are known at the time of onboarding flow commencing, but some others are only known after user identifies their device to us....

December 3, 2025 · 5 min

Systems Design - Pagination

Cursor-Based Pagination: Handling Deletions, Collisions & Secure Cursors Pagination requires subtle implementation for a smooth infinite scroll. In this post I’ll share what I learned while reading on cursor‑based pagination for a real‑time feed – how it differs from the classic offset/limit approach, how it deals with deletions and timestamp collisions, what goes into a cursor (spoiler: it’s not a random token), why you should (or shouldn’t) protect cursors from tampering, what to cache and how to manage stale data....

November 6, 2025 · 13 min

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

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. Node vs Side 💡 This was a very subtle yet “Aha” moment for me. When you’re traversing down a tree using dfs, while you can do things like: let leftNode = process(node.left) let rightNode = process(node.right) it might be better to see at as: let leftSide = process(node.left) let rightSide = process(node....

September 11, 2023 · 9 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 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 = ...3 // PartialRangeThrough<Int> let r4 = 3....

March 10, 2023 · 7 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