Leetcode By Shayan

Leetcode Solutions By Shayan

View on GitHub

Data Structures

Arrays (dynamic array/list)

Given n = arr.length


Strings (immutable)

Given n = s.length,


Linked Lists

Given n as the number of nodes in the linked list,


Hash table/dictionary

Given n = dic.length,

Note: the O(1) operations are constant relative to n. In reality, the hashing algorithm might be expensive. For example, if your keys are strings, then it will cost O(m) where m is the length of the string. The operations only take constant time relative to the size of the hash map.


Set

Given n = set.length,

The above note applies here as well.


Stack

Given n = stack.length,

stack implementation


Queue

Given n = queue.length,

queue implementation


Binary search tree

Given n as the number of nodes in the tree,

The average case is when the tree is well-balanced - each depth is close to full. The worst case is when the tree is just a straight line.

binary tree implementation


Heap/Priority Queue

Given n = heap.length and talking about min heaps,

heap implementation


resources: