Clone Binary Tree

Given a binary tree, return a deep copy of it.

Longest Common Subsequence

Given two strings, find the length of the longest common subsequence (LCS).

Implement Trie

Implement a trie with insert, search, and startsWith methods.

Gray Code

The gray code is a binary numeral system where two successive values differ in only one bit.

Integer to Roman

Given a roman numeral, convert it to an integer.

Integer to Roman

Given an integer, in the range of 1 to 3999, convert it to a Roman numeral.

Find Peak Element

Given an integer array A, a peak element with index p is defined as A[p] > A[p - 1] && A[p] > A[p + 1]. Find a peak element in this array and return its index. The array may contains multiple peeks; return any of them.

Route Between Two Nodes in Graph

Given a directed graph, design an algorithm to find out whether there is a route between two nodes.

Sort Letters by Case

Given a string which contains only letters. Sort it by lower case first and upper case second.


Singleton is a most widely used design pattern. If a class has and only has one instance at every moment, we call this design as singleton. For example, for class Mouse (not a animal mouse), we should design it in singleton.