life is too short for a diary

# Posts Tagged: leetcode

## Time Based Key-Value Store Solution

Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key's value at a certain timestamp...

## Find if Path Exists in Graph leetcode solution

It's a easy problem on Graph in leetcode to find if a path exist in graph...

## Serialize and Deserialize Binary Tree Leetcode solution

Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure...

## Apply Discount To Prices leetcode solution

A sentence is a string of single-space separated words where each word can contain digits, lowercase letters, and the dollar sign '\$'. A word represents a price if it is a sequence of digits preceded by a dollar sign...

## Sort Characters By Frequency solution leetcode

Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string...

## Minimum Consecutive Cards to Pick up solution leetcode

An interesting problem on leetcode to find minimum number of ways to pick up consecutive cards. We will start with a brute force algorithm that would exceed in time limit. Later we will improve upon this algorithm using hashmap...

## Leetcode - All Divisions With the Highest Score of a Binary Array

You are given a **0-indexed** binary array `nums` of length `n`. `nums` can be divided at index `i` (where `0 <= i <= n`) into two arrays (possibly empty) numsleft and numsright..

## Leetcode - Longest Substring Without Repeating Characters

In this [leetcode](https://leetcode.com/problems/longest-substring-without-repeating-characters/) problem, we are asked to find the length of the longest string of characters in a provided string that does not contain repeating characters. In other words, in the string `abcabcbb` the longest substring without repeating characters is `abc` (with a length of 3)...

## Course Schedule Leetcode Solution

There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai...

You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together...

## Lowest Common Ancestor of a Binary Tree

Questions involving the binary tree data structure are very popular in tech interviews, and can be challenging and varied! A binary tree is a data structure consisting of a collection of nodes (starting at a root node), where each node consists of a value (data), together with a directed edges to at most two nodes (the "left child" and "right child"), with the additional conditions that no two edges point to the same node and no edge points to the root. I recently solved an interesting problem on binary tree...

## Coin Change solution leetcode

It's one of the most popular questions on leetcode that seems very easy at first. Coin change is a classic dynamic programming problem. I will proceed with an obvious (albeit wrong) solution and subsequently proceed to an efficient correct solution...

## Maximum Subarray

There's an interesting problem I recently solved on leetcode based on dynamic programming. My Github repository contains list of all problems that I have solved. I often start with a brute force approach without fretting about time complexity. Later I try to improve my algorithm for a better efficient solution...

## Merge Two Sorted Lists

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists...