Pages

Thursday, March 24, 2011

顶风狂发G面经,顺求bless

FYI. Wed Mar 23 20:56:21 2011, 美东 
1.给字符串求频率最高字符。字符串大咋办,多核咋办。

2.俩数组交集。有序或无序。

3.实现cache.

Thursday, March 17, 2011

some hints about hg(mercurial)

we are switching from subversion to mercurial now.  something is different to them. so I record some hints here how we change our daily software development work.

* in subverion, we usually to merge one changeset. but in mercurial, it is not the same thing.
  * if the changeset is on different branch, we can merge the two branch. that means merge thsi changeset. :) totally different to subversion, ha. we can't only merge this changeset, we have to merge the two branch. but don't worry about the old changesets on the branch, mercurial is very smart to recognize the old same changesets , so it won't make conflicts. the command like this: hg merge xxx(the branch name of the changeset which you want to merge), of course the current branch should be the branch you are working on.
  * if the changeset is on one of ancient branch, you can only use the rebase to do this merge. that means rebase one parent from the new changeset. something like this:  hg rebase -s (the revision number which you want to merge) -d (the target branch you want to merge, or let's say the branch you are working on)

* if we have some uncommitted changes on the working directly, we can't do merge stuff, because mercurial forbidden to do this, that means he need a clean working directory. then how we can clean those uncommitted changes?
   * if they are really some uncommitted changes you do, then just do this command: hg revert --all.
  * if they are some uncommitted merge, then you can do hg revert to clean them, seems it is boring how to abort the uncommitted merge. I have a trick to do this: hg update -C.  the -C option will clean the working directory.

* if you have some local commits which you don't want to push, you can use hg strip to delete them from you local working directory.

so that's it, have fun and enjoy the mercurial.




Tuesday, March 8, 2011

Easily Installing Vim 7.2 From Source

in debian lenny, the vim is 7.1, if you want to use some new feature plugin, you have to update your vim from 7.1 to 7.2. but no vim7.2 debian package for lenny, so we have to install vim 7.2 from source.


Monday, March 7, 2011

what's the meaning of SDE and SDET from Microsoft?

* SDE may be:
  * Software Development Engineer
  * Software Design Engineer
 
* SDET 
* Software Development Engineer in Test
* Software Design Engineer in Test

Saturday, March 5, 2011

some iterview questions from Amazon

附电话面试题:

一面:

1. write a function to count zero bits in an integer, read code on the phone

2. use OOD to design an HTML parser, list all the classes and methods
其实就是DOM的简化,当时没反应上来,答得不好

3. what’s the difference between old style Python classes and the new style

4. Unix, how to find the file with the longest path name?

5. Unix, a million webpages, each page may have some phone numbers with two
formats (XXX)XXX-XXXX, XXX-XXX-XXXX, how to find them out and update them

6. A million of ids and more coming, how to tell if an id is duplicated.
what data structure, what’s the complexity

7. what if amazon website is slow?
(follow up). what if app server is idling but database server has high load?
(follow up). how to design cache on the app server?

二面:

1. (老题) find out pairs in an array that sum to a given sum.
write code on paper and read to the interviewer (character by character).

2. (OOD) Design classes for actors and movies, implement at least these two
methods:
actors->getMovies()
movies->getActors()
what to do if initializing actors needs the movies objects while
initializing movies needs the actor objects.
how to search for actors that starred in movies that were on show at a given
time.
discuss different approaches.

3. How to improve the current IMDb website, how to design the mobile version
(iphone/Android)

Thursday, March 3, 2011

Ed2k links handling in Linux

The way to make aMule handle your ed2k links on your favorite web browser will depend on which web browser you use and which operating system you have installed. So, here's a list of mini-HowTos for each of the most popular web browsers and operating systems.

Tuesday, March 1, 2011

讨论:merge两个有序数组

一个简单的情况:
假设a中元素都比b中的大
b会越界

标准的应该是3个循环
: 有更优的方法么? thx!
: k=i+j
: a[i],b[j],c[k]
: int ii=jj=kk=0;
: while(kk<k){
:         if(a[ii]>b[jj]){
:                 c[kk]=b[jj];
:                 jj++;
:         } else {
:                 c[kk]=a[ii];


so:
k=i+j
a[i],b[j],c[k]

int ii=jj=kk=0;
while(kk<k){
  if( ii==i || (jj<j && a[ii]>b[jj]) ){
    c[kk]=b[jj];
    jj++;
  } else {
    c[kk]=a[ii];
    ii++;
  }
  kk++;
}


so:

void merge(int *a, int sza, int *b, int szb, int *c) {
    //User is responsible for allocating array c
    int i = 0;
    int j = 0;
    while( i < sza && j < szb ) {
        if( a[i] <= b[j] ) {
            c[i+j] = a[i];
            ++i;
        } else {
            c[i+j] = b[j];
            ++j;
        }
    }
    while( i < sza ) {
        c[i+j] = a[i];
        ++i;
    }
    while( j < szb ) {
        c[i+j] = b[j];
        ++j;
    }
}

实现一个整数除法的函数,不使用除号,可以使用加号、减号和乘号,函数只返回 : 商.

you can only get 60pts with this algorithm

【 在 yesim (yesim) 的大作中提到: 】
: 五、实现一个整数除法的函数,不使用除号,可以使用加号、减号和乘号,函数只返回
: 商.
: function(int x,y){
:   n=x;k=0;
:   while(n>y){
:     n=n-y;
:     k++;
:   }
:   return k;
: }
: ...................

汽车出租(Car Rental Agency)的系统的oo设计

设计一个汽车出租(Car Rental Agency)的系统。他先问我如果要实现
vehicle search,需要哪些类;然后又问要实现rent a car,又需要哪些类;最后问如
果快到了交车截至时间,需要向用户发送提醒的邮件,应该怎么做。

abstract calss car
calss BMW extends car
calss Honda extends car
....

interface CarManager
class <T extends Car> CarManagerImpl {
  List T search(Class<T> clazz){
   
  }

  T search(Class<T> clazz){
   
  }
 
}

class User {
  List<UserCar> usercarList;

  User();
 
  boolean Rent(T entry){
    usercarList.add
  }

}

class <T extends Car> UserCar {
  List<UserCar> usercarList;
  ......
 
}


class Monitor implement Runnable {
  public boolean doMonitor{
    List<UserCar> usercarList = UserCar.getUsercarList(String condition)
    for(User user : usercarList){
      sendEmail(getUser().getEmail());
  }
}

讨论:反转一个整数,如12345->54321

反转一个整数,如12345->54321
当时写了个这么个东西(面试官假设输入是正整数):
int reverse(int n) {
   res = 0;
   while(n != 0) {
      res *= 10;
      res += n % 10;
      n = n / 10;
   }
   return res;
}

然后面试官问,如果n<0怎么办;我说判断一下,然后把n = -n,然后重复;
问题就在这里,他说不行,正确的做法是n = -1 * n;我不明白为什么是这样?


n为负数,你想把它整成整数
不用 n = -1 * n;  用啥?
或者你用  n = 0 - n; 也行

-n 编译都不通过

居然都不做防止溢出的?
正负数的溢出不等

The syntax
n = -n;
is valid in C and C++.