Monday, February 2, 2015

Interview Questions

Mixpanel
Ten most frequent triplets
1 a
2 b
1 b
1 c
2 c
2 d
1 d
----------
abc 1
bcd 2


Salesforce
java memory leak possible?
inheritance
hashmap vs tree what's the reason to choose one over another
why use ajax
external sorting of 16G file numbers with 1G mem
1-n relationship how many tables


ipsy
First missing positive integer in array (swap O(N) solution)
Patterns (Singleton (eager, lazy), Observer)


Pure Storage
JIT compiler
left outer join
synchronization and why
java, c++, hadoop, spark, ML, frontend experiences


PRO Unlimited
Spring components, ElasticSearch, Javascript experiences
String (immutable), StringBuilder, StringBuffer (thread safe)
List vs Set (duplicate or not)
HashMap vs Properties (hash, fast lookup)
Comparator/Comparable
ExecuteService, thread pool, Runnable, Callable
SQL group by
coding: change elements after multiples of 10 element [7,8,9,10,15,16,30,15,10,12,8] -> [7,8,9,10,10,10,30,30,10,10,10]
coding: given root dir, get all "*tmp*" filenames in the dir and its subdir
brain teasing: 9 balls, 1 is different weight, a balance to weigh (at most 4 times to find the different ball)


FB
1. version control sys, find first bad version, there is function boolean isBad(int v) (int findBad(int good, int bad)) - binary search, while(start<end-1), return end;
2. parlindrome string (escape punctuations and spaces)


Bill.com
what is RESTful API? how to handle heavy traffic?
reverse char array and return new reversed array (test cases?)
reverse char array in place (test cases?)


Smule
1. MultiMap - thread safe
class MultiMap<K, V> {
    private Map<K, List<V>> map = new ConcurrentHashMap<K, List<V>>();  
    public List<V> get(K key) {
        return new ArrayList(map.get(key)); // put value while iterating through list
    }
    public synchronized void put(K key, V value) { //synchronized
        if(map.contains(key)) {
            List<V> valueList = map.get(key);
            valueList.add(value);
            //map.put(key, valueList);
        } else {
            List<V> valueList = new ArrayList<V>();
            valueList.add(value);
            map.put(key, valueList);
        }
       
    }
    public synchronized void remove(K key) { // synchronized
        map.remove(key);
    }
}

2. design library, book on shelf, due date, check out date

create table Book (
id number (primary key),
bookname varchar(256),
isbn varchar(64)
);

create table Record (
  recordid number (primary key),
  bookid number,
  borrowerId number,
  checkoutDate date,
  dueDate date,
  returnDate date
);

create table Borrower (
id number(primary key),
name varchar(64),
phone varchar(10)
);

// books borrowed by a user which are overdue
select bookname from Record join Book
on Record.bookid=Book.id
where Record.borrowerId=12345
and returnDate=null
and now()>dueDate;

// all borrowing record of a book
select * from Record where bookid=12345 order by checkoutDate;

// return a book
update Record set returnDate=now()
where bookid=12345 and borrowerid=54321 and isReturned=false;