Fork me on GitHub

Jump Game

Jump Game

Description:

Given an array of non-negative integers, you are initially positioned at the first index of the array.

Each element in the array represents your maximum jump length at that position.

Determine if you are able to reach the last index.

Notice:

O(nlgn)-time algorithm to find the LIS

In the spirit of dynamic programming, we first consider what information we would need from previous problems to solve for a longest increasing sub-sequence in A[n]. There are two cases:

Case 1. The length of the LIS(s) of A[n] is equal to the length of the LIS(s) of A[n-1].
        This will occur when for all A[k], where A[k] is the last element in a longest increasing sub-sequence 
        of A[n-1], A[n] <= A[k].

Case 2. The length of the LIS(s) of A[n] is equal to 1 + the length of the LIS(s) of A[n-1].
        This will occur when A[n] > than some A[k], where A[k] is the last element in a longest increasing 
        sub-sequence of A[n-1].

Permutations

Permutations

Description:

Given a list of numbers, return all possible permutations.

Notice:

You can assume that there is no duplicate numbers in the list.

Example:

For nums = [1,2,3], the permutations are:

[
 [1,2,3],
 [1,3,2],
 [2,1,3],
 [2,3,1],
 [3,1,2],
 [3,2,1]
]

Questions should be clarified when being interviewed

There are some questions should be clarified when being interviewed. Make sure to communicate with the interviewer and understand the question clearly.

  1. Array:
    (1) Sorted or not?
    (2) How many elements?
    (3) Element type? Int, float, double?
    (4) What’s the range of those numbers? Positive or negative?
    (5) Contain duplicates or not?
    (6) Subsequence: adjacent or not?

Continuous Subarray Sum

Continuous Subarray Sum

Description:

Given an integer array, find a continuous subarray where the sum of numbers is the biggest. Your code should return the index of the first number and the index of the last number. (If their are duplicate answer, return anyone)

Example:

Give [-3, 1, 3, -3, 4], return [1,4].

分析:

Maximum Subarray,只是需要记录起始和结束的下标。

N-Queens

N-Queens

Description:

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.

Given an integer n, return all distinct solutions to the n-queens puzzle.

Each solution contains a distinct board configuration of the n-queens’ placement, where ‘Q’ and ‘.’ both indicate a queen and an empty space respectively.

Subsets

Subsets

Description:

Given a set of distinct integers, return all possible subsets.

Notice:

  • Elements in a subset must be in non-descending order.

Shadowsocks,Vultr,IPV6搭建校园网免流量环境

胡说八道

原因

由于校园网不够用且资费太贵,看到可以通过IPv6实现免流量上网,所以决定试一下。

其实大可不必那么麻烦(有其它的更方便的方式实现翻墙+免流量,而且免费),只是感觉作为一个程序员还是需要弄一个VPS玩玩的,否则出去说都没弄过VPS多可笑,嗯,弄一下,长长见识。

ShadowSocks