Some vs Any

What problem do some and any solve? var x: Equatable = 10 // Error: Use of protocol 'Equatable' as a type must be written 'any Equatable' var y: Equatable = "10" // Same error It’s because the compiler can’t know if the associated type of x, matches with the associated type of y. So it just forbids it. Compiler just doesn’t want to be in situation where you’d try something like:...

July 17, 2024 · 3 min

Hugo Post Formatting Basics

Frontmatter There are some standard Hugo frontmatter, but there’s also a lot of theme-specific frontmatter. In this post I might be referring to theme-specific frontmatter that you won’t find in another theme. But the general idea of frontmatters is universal. You can add tags: [swift, json, network call] and it will then add the tags to your post. Add showToc: true and will show a table of contents for your post....

May 3, 2024 · 3 min

Hugo High Level

This is the 2nd post of “Everything I learned from blogging with Hugo” series Why Hugo? Hugo is a Static Site Generator. Key is the word “static”. It means: A static website is made up of one or more HTML webpages that load the same way every time. Static websites contrast with dynamic websites, which load differently based on any number of changing data inputs, such as the user’s location, the time of day, or user actions....

April 30, 2024 · 7 min
First to the key first to the egg

Being First is a Game Changer

If you’re ahead of others, you become people’s go to person. It means more involvement. More challenge and opportunities to grow and network. Being first means you can pave the way for others and be helpful. It’s one of the key traits of a lead. Main Advantages of being first You can set the tone, guidelines that you want others to follow. And not you following others. Often you’re late into some bad architecture....

February 28, 2024 · 6 min

The effect of direction on recursion and understanding code

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 algoritm I deduced on my own vs a few other algorithms I saw online. Our algoritms seemed very similar. Yet different. It made debugging my code based on other code very difficult. This is a very commong problem I face when I doing leetcode....

December 2, 2023 · 6 min
An AI generated image of asteroids

Asteroids Collision

Today we’re solving https://leetcode.com/problems/asteroid-collision/ Imagine if we had the following: 1 5 3 8 6 -> -> <- <- -> Each number represents the size of an asteroid. Each asteroid is either going left or right. Bigger asteroids destroy smaller asteroids. Asteroids with same size both get destroyed. If two asteroids are going in the same direction, they don’t hit each other, because all are going in the same speed....

November 20, 2023 · 5 min
Multiple envlopes along with their width and height

How Many Envelopes Can You Fit Into Another?

Question: How many envelops can you fit into another? Each envelope has a 2D representation. [4,5] -> width = 4, length = 5 How many envelops can you fit into one another without rotating any envelopes. Bare in mind you can’t fit in two evelopes with same width or height. This is question is very much like a Russian Doll question. Which that question itself uses an Longest increasing subsequence algorithm to solve....

November 12, 2023 · 4 min

Updated - Longest Increasing Subsequence Length

Attention: This post was updated to include the alternate solution that uses binary search. It reduces the Time Complexity from O(n * n) to O(n * log n). Before we present the question. Let’s figure out what a subsequence is: What’s a subsequence? Any selection of items from the original array. The selection must respect the order. Meaning for [1,2,3,4,5] only two of the four below are subsequences: [1,2,3,4,5] ✅ [1,4,3,2,5] ❌ order not respected [1,2,5] ✅ [5,1] ❌ order not respected What’s the difference between a subsequence and a subarray?...

November 11, 2023 · 10 min

Tips for post creation

This is the 1st post of “Everything I learned from blogging with Hugo” series I started blogging in Dec 2021. It’s been a wonderful journey. Has enabled me to gather my thoughts in a far more structured way. The series is based on my setup of Hugo - Netlify - GitHub. I’ll shared my knowledge in terms of Hugo knowledge, how to write a blog post and more. If anyone is interested in the Netlify setup, see Hugo Quick Start then Netlify - Hugo setup....

October 1, 2023 · 9 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. 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