Procedure to conduct an A/B test

** Step 1: ** UX Code Instrumentation - Server / Client : Usually in UX code base, we need to log some logs, and in client, we can ping a url to log to server side.
** Step 2: ** A/B Flight
** Step 3: ** Generate A/B test scorecard
** Step 4: ** Analysis, and decide next step (ship or iterate)

Read More

Git - a stupid content tracker

fast, scalable, distributed revision control system with unusually rich command set that provides both high-level operations and full access to internals.
Total nearly 150+ commands.

porcelain command: user friendly command
plumbing command: low-level command

Revision control? How hard?

simple method: just copy all the old files and paste it into a new folder and rename it with date.
it must supply main function:

tracking changes and versions

traditional revision control shortcomings (central repository):

need to re-sync everytime your commit.
single point failure: if server down, you can not recover the code history from client.(you can just recover snapshot)

why git is different?

git is distributed.

what does distributed mean?

you do not have one central place which keeps track of your data.
client have all the data(includes the history).

Read More

Leetcode 121 - 123 是三个简单的股票买卖问题。都可以用O(n)的时间复杂度求解。

121 最简单
Say you have an array for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Example:
Input: [7, 1, 5, 3, 6, 4]
Output: 5

解法也比较直接,一次遍历可以完成。

Read More

问题描述

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.

https://leetcode.com/problems/longest-palindromic-substring/

DP解法

注意回文串有两种形式:a和aa,也就是中轴是一个元素或者两个元素。
可以转化为求解s和s逆序(例如dabcbaee和eeabcbad)的最长公共子串,并且这两个子串在原串中是相邻的,(例如abcjiecba中,abc和cba虽然最长公共子串,但并不相邻)

dp[i][j]表示以s以i结尾,s逆序(s’)以j结尾的两个字符串的最长公共子串的长度。可以得到递推式:
dp[i][j] = dp[i-1][j-1] + 1 (if s[i]===s’[j])
dp[i][j] = 0 (if s[i] !== s’[j])

判断相邻的条件:(i + j - dp[i][j] + 1 === len) || (i + j - dp[i][j] === len)

Read More

当求一个数列的尖峰值,或者跟尖峰值相关的问题时,常常需要用到双向扫描的做法。

例如 LeetCode 105 Candy

There are N children standing in a line. Each child is assigned a rating value.
You are giving candies to these children subjected to the following requirements:
(1) Each child must have at least one candy.
(2) Children with a higher rating get more candies than their neighbors.
What is the minimum candies you must give?

解法: 首先正向扫描,算出需要满足只看左边所需要的最少糖果的分配方案。
再反向扫描,算出满足只看右边所需要的最少糖果的分配方案。
然后分别对每一项求出两者之间的较大值。
可以优化为:反向扫描的时候,如果不满足高分小孩拿到比右边小孩更多糖果这个条件,再对值进行修正。

Read More

问题描述

从0~n-1的范围内的n个整数中,随机选取m个整数,不允许重复选择,每个数字被选中的概率相同

n可知

Solution 1

小数据分析
假设n=5,m=1,那么
$$ P(0)=\frac{1}{5} $$
$$ P(1)=\frac{1}{4} (如果0未被选中, 否则P(1)=0) $$
$$ 总体概率为 \frac{4}{5} * \frac{1}{4} = \frac{1}{5} $$

Read More