Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of this person who have a height greater than or equal to h. Write an algorithm to reconstruct the queue. … Read more…

I have written a solution for this question before: http://www.lifeincode.net/programming/leetcode-median-of-two-sorted-arrays-java/ That solution seems easy to understand. However, it turns out to be very difficult to implement. The hardest part is how we come up with a correct way to handle borders. After reading some post, I found there is another way to achieve findKth number from two sorted arrays, and the running … Read more…

Why do we need Databus? There is no one type of data management system that meets every needs. In most cases we will have a primary source-of-truth system and some other data systems. But we need to maintain the consistency between the primary system and other systems. There are two possible type of solutions: Application-driven Dual writes: Application writes to … Read more…

Why Kafka? Lots of “log” data generated every day, including user activities like login, page views, clicks, likes, and other queries machine metrics like CPU, memory usage. This is not only for offline analytics, but also very useful in online services. Usage may includes search relevance recommendation performance ad targeting and reporting security things. The traditional way is to dump the … Read more…

In the last post, I have mentioned that I want to write the solution for finding two missing numbers from 1 to N. It has been several months(almost half year, how time flies) and finally I have time to write it down. Problem description: Find two missing number from 1 to N Given an array of size N-2, containing integer numbers … Read more…

Find one missing number from 1 to N Given an array of size N-1, containing integer numbers from 1 to N, but there is one number missing. Return the missing number. Analysis Assuming the array given is A[], it’s easy to get N since we have the size of the array: N = A.length + 1. Approach 1(Brute force): The solution … Read more…

Palindrome Partitioning Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = “aab”, Return

1

2

3

4

[

["aa","b"],

["a","a","b"]

]

Palindrome Partitioning II Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s = “aab”, Return 1 since the palindrome partitioning [“aa”,”b”] could be … Read more…

Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transactions. Note: You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again). Analysis In this problem, we are only allowed … Read more…