MO.AT

Mohit Athwani's

Adventures in C++, iOS, Unix, and the biggest of all..Life!.

Mohit Athwani

From India to California. In search of greener pastures. Writing about C++, Swift, algorithms and my life in general.

Read More

Posts

Leetcode - 819. Most Common Word

Algorithms, Arrays, Strings

Wow it’s been a while sonce I wrote anything here. I have been doing a lot of functional reactive programming at work and have been wondering how I can apply these new concepts to Leetcode problems. Here is my attempt at finding the most common word from a paragraph that is NOT in the list of banned words.

Read More

Leetcode - 11. Container With Most Water

Algorithms, Array

Think of the numbers in the array representing a height. Now, you can create an imaginary box by selecting any two numbers in the array. The max height of water that this imaginary box can hold is the minimuj of the two numbers. So what is the area of the water that can be held?

Read More

Building a TabBarView with SwiftUI

Open Source, Swift

In my last post I talked about how and why I used Google Sheets as the backend and database for the Aspire Budget apps. When I wrote that post, I had just launched version 1.0 of the app which has received some great response. However, if you did download the app, you would notice that the user interface of the app is really not appealing.

Read More

Get Random Node from Binary Search Tree

Algorithms, Binary Search Tree

Problem Statement

The goal of this challenge is to build your own BinarySearchTree class which in addition to supporting insert, find and delete also supports a special operation getRandomNode() which returns a random node from the binary search tree with special consideration that each node in the binary search tree is equally likely to be selected.

Read More

Check if a Tree is a sub tree of another

Algorithms, Tree, Graph, DFS

Problem Statement

There exists two very large binary trees, with one tree, T1 relatively much bigger than the other T2. How can we efficiently determine if T2 is a sub tree of T1?

Read More

Weaving two arrays

Algorithms, Backtracking, Recursion

This is an interesting recursion problem where the aim is to find all the possible weaves of 2 arrays keeping the relative order of the elements the same.

Read More

Taming Open Source Swift (SR-7292)

Open Source, Swift

In December 2015, Apple made Swift an open source language and made it available on Github. This piqued my interest, I dug around the code base for a little, cloned it and felt like I had achieved something great. Fast forward to Spring 2017, I made my first contribution to the swift-corelibs-foundation, two contributions to be precise. The way I made these contributions was by digging around the code base for the NSString class and implementing methods marked as NSUnimplemented(). With two accepted PRs to swift-corelibs-foundation, the next thing I did was opened up my resume and under the Key Projects section, added a new bullet point right on top – Currently contribute to Apple’s open source Swift project on Github.

Read More

Leetcode - 270. Closest Binary Search Tree Value

Algorithms, Binary Search Tree, Leetcode

If the type of the target and the type of the value in the tree nodes were the same, and the problem was to find the node in the tree that is just smaller than the target, the problem becomes fairly simple. For example, given target = 17 and the graph:

Read More

Leetcode - 64. Minimum Path Sum

Algorithms, Array, Dynamic Programming

Problem Statement

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.

Read More

Leetcode - 42. Trapping Rain Water

Algorithms, Array, Recursion, Two Pointers, Leetcode

There’s one thing common between this problem and the Container With Most Water problem and that is the height of the shorter tower dictates the result. In this problem, the amount of water that can accumulate between two towers is limited by the height of the shorter tower. Consider an array [4, 5, 9, 7 ,1, 0 ,4, 0 ,8 ,6 ,5 ,2 ,3] which is represented as:

Read More

Generate Parantheses

Algorithms, Backtracking, Recursion, String, Leetcode

Before we start solving this problem, let’s do some math first. The problem statement clearly states that we have N pairs of parentheses to work with. That means for a string to be considered as part of the solution, it must be of size 2N.

Read More