The disks in RAID 1 array may fail at any time.
Continue reading
Author Archives: James
Balanced Binary Tree Problem
Problem description:
level: medium
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
Continue reading
Maximum Depth of Binary Tree Problem
Problem Description
level: easy
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Have you met this question in a real interview?
Continue reading
Add Email Account in your Linux Server
Assuming email server (for example, sendmail) is installed.
Step 1: add an entry to /etc/mail/virtusertable like:
user@domain.com user
Continue reading
Merge Sort
The merge sort is a recursive sort of order n*log(n).
It is notable for having a worst case and average complexity of O(n*log(n)), and a best case complexity of O(n) (for pre-sorted input). The basic idea is to split the collection into smaller groups by halving it until the groups only have one element or no elements (which are both entirely sorted groups). Then merge the groups back together so that their elements are in order. This is how the algorithm gets its “divide and conquer” description.
Binary Tree Inorder Traversal Problem
Problem Description
Easy level
Given a binary tree, return the inorder traversal of its nodes’ values. Binary Tree Inorder Traversal is to parse left child node, then root, then right child node
Example
Given binary tree {1,#,2,3},
1 2 3 4 5 6 7 |
1 \ 2 / 3 |
return [1,3,2].
Continue reading
Binary Tree Preorder Traversal Problem
Problem Description
Given a binary tree, return the preorder traversal of its nodes’ values.
Example
Given binary tree {1,#,2,3}:
1 2 3 4 5 6 7 |
1 \ 2 / 3 |
First Bad Version
Problem description
The code base version is an integer start from 1 to n. One day, someone committed a bad version in the code case, so it caused this version and the following versions are all failed in the unit tests. Find the first bad version.
You can call isBadVersion to help you determine which version is the first bad one. The details interface can be found in the code’s annotation part.
Find Minimum in Rotated Sorted Array
Problem description:
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Find the minimum element.
Example
Given [4, 5, 6, 7, 0, 1, 2] return 0
Continue reading
Binary Search Problem
Problem:
For a given sorted array (ascending order) and a target number, find the first index of this number in O(log n) time complexity.
If the target number does not exist in the array, return -1.
Example
If the array is [1, 2, 3, 3, 4, 5, 10], for given target 3, return 2.
Challenge
If the count of numbers is bigger than 2^32, can your code work properly?
Continue reading