Thursday, April 2, 2015

Snapchat

http://www.2cto.com/kf/201205/131442.html
http://www.geeksforgeeks.org/greedy-algorithms-set-3-huffman-coding/
http://www.cgorbit.itkm.ru/docs/unix-way/Programming%20Pearls%20%282nd%20Ed%202000%29%20-%20Jon%20Bentley%20ADDISON%20WESLEY.pdf

http://www.1point3acres.com/bbs/thread-108837-1-1.html
http://www.1point3acres.com/bbs/thread-125921-1-1.html
http://zhedahht.blog.163.com/
http://ac.jobdu.com/hhtproblems.php
http://baozitraining.org/blog/2014-star-startup-interview-snapchat/


http://blog.csdn.net/whuwangyi/article/details/14225373

电面:
非常简单的两道题:
find the shift position in the rotated sorted array
like windows paint, draw the color of triangle, square, or circle

class color {
  private:
    int R;
    int G;
    int B;
};
class point {
public:
  int x;
  int y;
};
class paint_tool {
  private:
    vector<vector<int>> canvas;
    int index[] = {-1, 1}
  public:
    void piant(point p, int color) {
      queue<point> que;
      que.push(p);
      vector<vector<bool>> marker;
      for(int i = 0; i < canvas.size(); i++) {
        for (int j = 0; j < canvas[0].size(); j++) {
          marker[i][j] = false;
        }
      }
      canvas[p.y][p.x] = color;
      marker[p.y][p.x] = true;
      while (!que.empty()) {
        point cur = que.front();
        que.pop();
        for (int j = -1; j <= 1; j++) {
          for (int i = -1; i <= 1; i++) {
            if (i == 0 && j == 0) {
              continue;
            } else {
              point neighbor(cur.x + j, cur.y + i);
              if (validBoundary(color, neighbor) && marker[neighbor.y][neighbor.x] == false) {
                que.push(neighbor);
              }
            }
          }
        }
        //paint the point
        canvas[p.y][p.x] = color;
        marker[p.y][p.x] = true;
      }    
    }
    bool validBoundary(int color, point &p2) {
      if (color != canvas[p2.y][p2.x]) {
        return true;
      } else {
        return false;
      }
    }
};

No comments:

Post a Comment