Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

Integer Square Root, sqrt(x)

Implement square root function, sqrt(x), that returns an integer result. The algorithm should run in O(log x).

Hash Function

In data structure Hash, hash function is used to convert a string(or any other type) into an integer smaller than hash size and bigger or equal to zero. The objective of designing a hash function is to “hash” the key as unreasonable as possible. A good hash function can avoid collision as less as possible. A widely used hash function algorithm is using a magic number 33, consider any string as a 33 based big integer like follow:

Climbing Stairs

You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

O(1) Check Power of 2

Using O(1) time to check whether an integer n is a power of 2.

Unique Characters

Implement an algorithm to determine if a string has all unique characters.

Two Strings Are Anagrams

Write a method anagram(s,t) to decide if two strings are anagrams. Two strings are anagrams if they have the same letters in different order.

Remove Element

Given an array and a value, remove all occurrences of that value in place and return the new length.

Nth to Last Node in List

Find the nth to last element of a singly linked list.

Merge Two Sorted Lists

Merge two sorted (ascending) linked lists and return it as a new sorted list. The new sorted list should be made by splicing together the nodes of the two lists and sorted in ascending order.