## Solution to Closest Binary Search Tree Value II

5 May

This question is available on both Leetcode (No. 270) and Lintcode (No. 901). The question is not too hard, if we do not chase the best time complexity. For example, we can traversal all the nodes and book-keep the closest … Read More »

## Solution to Hills

7 Sep

Question Name: Hills Question Description: An integer array store the heights of some consecutive hills. Find a minimum integer N, so that you could increase/decrease the heights of the hills by any integer in range [0, N]. After the adjustment, … Read More »

## Solution to Deviation

4 Sep

Question Name: Deviation Question Description: Given an array of integer elements and an integer d, please consider all the sequences of d consecutive elements in the array. For each sequence we compute the difference between the maximum and the minimum … Read More »

## Solution to Find the Abnormal Number

29 Aug

This morning, I suddenly remembered this challenge. But I nearly forgot the answer. I’d better to record it here for latter review. Question Name: Find the Abnormal Number Question Description: in a given integer array, every number, except one, appears … Read More »

## Solution to Simulate Stack With Two Queues

2 Aug

Question Name: Simulate Stack With Two Queues

## Solution to Count Visible Nodes in Binary Tree

25 Jul

Questioin Name: Count Visible Nodes in Binary Tree Question: In a binary tree, if in the path from root to the node A, there is no node with greater value than A’s, this node A is visible. We need to … Read More »

## Solution to Print Tree By Columns

25 Jul

Question Name: Print Tree By Columns Question: print tree by columns, from leftmost column to rightmost column. For each node in i(th) column, if son(s) exist, its left son is in the (i-1)th column, and right son in the (i+1)th … Read More »

## Generate a subset in a uniformly random manner

21 Feb

Question: To generate a K-subset in a uniformly random manner from N elements. We have two slightly different solutions. The first one is quite straightforward:  shuffle the elements, and then return the first K elements. In such solution, the space … Read More »

## Find a Duplicate Item In an Array of Shuffled Consecutive Integers

16 Mar

Question: if you hava an array with n integers. These integers are in random order. And each interger is between 1 and n-1, including 1 and n-1. Additionally, there is one and only one integer, which appears twice, while all … Read More »