Friday, November 11, 2016

There is only one ultimate solution for expensive medical system in US: hire more doctors from China!!! Set up strict exams to maintain the quality

The total INCOME of one BEST Chinese doctor is much SMALLER than the TAX paid of one WORST US doctor.

One Chinese doctor has way much more experience than a US doctor

As they need to serve 10 times more patients than US doctors.

Still worry about quality? Strict exams can provide the solution.

So, the ultimate solution is, set up a strict doctor exam like ETS GRE, and introduce doctors passing the exam to US.

Maybe right now it is a good time to invest in russian

If I decided to invest in energy and natural resources, I will prefer Russian ETFs.

Once oil prices go up, Russian stocks will go up as well.

Down side:
  1. World war (The possibility is quite low)
  2. Continue against Russia? Should not happen right now.
  3. Well I really do not know any specific down side right now as the economy of Russia is as low as the ground now.
  4. But Russia will not broke, as China is always supporting it.
Popular Russian ETFs include:
  1. Market Vector Russia ETF Trust (NYSE: RSX)
  2. iShares MSCI Russia Capped Index Fund (NYSE: ERUS)
  3. SPDR S&P Russia ETF (NYSE: RBL)
  4. Market Vectors Russia Small-Cap ETF (NYSE: RSXJ)

      Russia's most popular ADRs include:
      1. Gazprom OAO ADR (OTC: OGZPY)
      2. Lukoil ADR (OTC: LUKOY)
      3. Mechel OAO (NYSE: MTL)
      4. OJSC Polyus Gold ADR (OTC: OPYGY)

      The ultimate reason why Trump wins

      Imaging you are a 40 years' old truck driver living in Illinois.

      You have a wonderful family and two beautiful kids.

      You loan a nice truck. Before Obama 2008, you can earn $9000 each month by shipping beers back and force between Chicago and New York.

      You income can afford you to travel abroad each year with your family.

      If you are willing to drive during Christmas you can earn much much more than that.

      But... things changed.....

      Since 2008, immigrates flood in.

      They are rich, they purchase their own trucks on day one, BUT you owe a large loan to bank.
      They are working day and night. Even during Christmas? Oh come on, not a big deal, they have never heard of Christmas before entering US!!

      You income is decreasing...

      Phone calls to you requesting shipping become less and less, but you can not just leave your truck home doing nothing, you have LOANs to pay! Your children needs education!

      You work more hours each day, drive more and more careful, call every one you know for new shipping.

      You income is still decreasing...

      You used to refuse to ship rubbishes as they make your truck smelly. But now you do not care that. Come on, the more the better!

      But you income is still decreasing...

      You start to drive during Veteran day, Thanksgiving, Christmas... whatever who cares.

      You income is still decreasing!!

      "Fine, fine. Let me sell the truck and find another job, " you think. But where are those jobs? Shipping rubbish during Christmas seems to be the highest salary jobs you can do, but even that cannot help you to afford your family.

      Try a computer science job in CA?  No joking, MISSION IMPOSSIBLE for a 40 years old truck driver without college degree.

      Re-attending college? Sorry, minorities are preferred.

      You understand, world is reshaping by technical, industrial upgrade is inevitable, drivers will definitely replaced by self-driving cars in the near future any way...

      "But, please, please do give me some help when that change proceeds. I have two kids to bring up!", you shout in your heart..

      Whose fault is this? No one's fault, but government should at least focusing on helping us, instead of GLOBAL WARMING

      You can only

      You do this not because you like Trump, but because

      Damn globalization, who cares. I want AMERICAN DREAM!

      Sunday, November 6, 2016

      10 principles for smooth web animations

      How to use font awesome to polish your website

      Paste the following css code in your html:

      <link href="" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">

      This downloads font awesome from bootstrap cdn.

      In CSS, you can try:

      .your-class {
        content: "\f00c";
        font-family: 'FontAwesome';

      which provides you the icon ok

      Or in html codes, you can use
      <i class="fa fa-ok fa-lg"></i>

      has similar results. Notice that <div> must have
          font-family: 'FontAwesome'
      in its class.

      Check this cheat sheet for more symbols:

      Check youtube links for help too:


      Thursday, December 19, 2013

      Sort a linked list in O(n log n) time using constant space complexity.

      This one is easy. Merge sort can solve this problem.

      See the following code for the merge sort from bottom to top

       * Definition for singly-linked list.
       * struct ListNode {
       *     int val;
       *     ListNode *next;
       *     ListNode(int x) : val(x), next(NULL) {}
       * };
      class Solution {
          ListNode *loop_list(ListNode *head, int len){
              // There are len nodes from head(inclusive) to ret(exclusive)
              while(head != NULL && len-- > 0) head = head -> next;
              return head;
          ListNode *merge(ListNode *head, int len){
              // Merge len nodes beginning from head->next(inclusive), and return the last node.
              if(head == NULL || head -> next == NULL) return NULL;
              ListNode *a_beg = head -> next;
              ListNode *a_end = loop_list(a_beg, len/2 - 1);
              if(!a_end) return NULL;
              ListNode *b_beg = a_end -> next;
              a_end -> next = NULL;
              ListNode *b_end = loop_list(b_beg, len/2 - 1);
              ListNode *new_end = b_end == NULL ? NULL : b_end -> next;
              if(b_end != NULL) b_end -> next = NULL;
              ListNode *loop = head;
              ListNode *a_loop = a_beg;
              ListNode *b_loop = b_beg;
              while(a_loop || b_loop){
                  ListNode *next;
                  if(!a_loop) {
                      next = b_loop;
                  else if(!b_loop){
                      next = a_loop;
                  else next = (a_loop -> val < b_loop -> val) ? a_loop : b_loop;
                  loop -> next = next;
                  loop = loop -> next;
                  if(next == a_loop){
                      a_loop = a_loop -> next;
                  else if(next == b_loop){
                      b_loop = b_loop -> next;
              loop -> next = new_end;
              return loop;
          ListNode *sortList(ListNode *head) {
              ListNode *fake_head = new ListNode(0);
              fake_head -> next = head;
              int num_merge = 0;
              for(int len = 2; true; len *= 2){
                  num_merge = 0;
                  ListNode *loop = fake_head;
                  while(loop && loop->next){
                      loop = merge(loop, len);
                      num_merge ++;
                  if(num_merge <= 1) break;
              head = fake_head -> next;
              delete fake_head;
              return head;

      Leetcode: Max Points on a Line

      Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.

      The following is a O(n^2 lg n) algorithm because I use TreeMap instead of HashMap.

       If I use HashMap, then the run time is O(n^2). But I did not find a way doing better than O(n^2).

      Another question is that to use HashMap in java I need to define my own equals() and hashcode() functions, which is quite annoying. Especially hashcode() function, any one have a idea how to produce a good hashcode() function for this?

       * Definition for a point.
       * class Point {
       *     int x;
       *     int y;
       *     Point() { x = 0; y = 0; }
       *     Point(int a, int b) { x = a; y = b; }
       * }
      import java.util.*;

      class Slope implements Comparable<Slope>{
        int x;
        int y;
        Slope(int a, int b){
                a *= -1;
                b *= -1;
            x = a; y = b;
        public int compareTo(Slope other){
            return this.x * other.y - this.y * other.x;

      public class Solution {
          int numPointsCentered(Point[] points, int id){
              Map<Slope, Integer> counts = new TreeMap<Slope, Integer>();
              int num_same_point = 0;
              int return_max = 1;
              for(int i = 0; i < points.length; i++){
                  if (i==id) continue;
                  if (points[i].x==points[id].x && points[i].y==points[id].y){
                  Slope slope = new Slope(points[i].x - points[id].x, points[i].y - points[id].y);
                      counts.put(slope, counts.get(slope) + 1);
                      counts.put(slope, 2);
                  return_max = Math.max(return_max, counts.get(slope));
              return return_max + num_same_point;
          public int maxPoints(Point[] points) {
              int num_points = 0;
              for(int i = 0; i < points.length; i++){
                  int new_center_points = numPointsCentered(points, i);
                  num_points = Math.max(num_points, new_center_points);
              return num_points;

      Friday, October 11, 2013

      Interview : a strategy to stop flipping the poker and win


      You are playing a card game with me. Suppose I shuffle a deck of 52 cards, then I show you the card one by one to you from top to bottom. You can stop me during this whole process, based on your memory of the previous cards you have seen. If you stop me, and there are still cards left in the deck, if the next unshown card is red, you get one dollar from me, otherwise if the next unshown card is black, you give me one dollar; if no cards left in the deck, you get one dollar if the last card is red, and you give one dollar if the last card is black.

      Is there a strategy for you to win with probability larger than 50%?


      There is not strategy for that. Think the game in a different way: when you stop me, suppose instead of deciding whether you win or lose based on the next unshown card, we decide whether you win or lose based on the last card in the deck: if the last card is red you get one dollar, otherwise if it is black I get one dollar. The two games are the same. But for the latter, whatever strategies you choose the probability for you to win is always 50%, and so does the former.

      Interview : Expected time to see a bus

      Suppose a bus is running on a loop route. It takes 10 mins for the bus to finish the route. If a guy arrives at a bus stop at uniformly random time. What is the expected bus waiting time?

      Sol: image uniformly put a point at a line with length 10, so the expected waiting time is 5.

      Now suppose there is a ice cream shop at the bus loop. Whenever the bus is close to the ice cream shop, the driver will flip a coin and decide whether to go eating an ice cream or not. It takes 10 mins for the driver to eat the ice cream. What is the expected bus waiting time if a guy arrives at a bus stop uniformly.

      Sol: the key is to consider what uniform arriving time means. The bus is running either on a 10min-loop or a 20min-loop, each with probability 1/2. The bus keeps running, and the guy can arrive at any time between 0am - 24pm, uniformly. The time for the bus to be in a 20min-loop is two times larger than the time for a 10min-loop. So each day 2/3 of the time the bus is in a 20min-loop, and 1/3 of the time the bus is in a 10min-loop.

      Thus, the probability for the guy to arrive when the bus is in a 20min-loop is 2/3. Expected waiting time is 10 for the 20min-loop and 5 for the 10min-loop. So the combined expected waiting time is

      2/3 * 10 + 1/3 * 5

      Manacher's Longest Palindromic Substring Algorithm