round1: reverse Integer, Valid Parentheses(leetcode 20) (two interviewers) round2: 1.design a horse racing system 2. given a height matrix, decide whether the rain can flow form the inside column to the left and right margin(two interviewers) round 3: talk with a manger, some behavior question, how to find the kth largest number in an unsorted array. round 4: talk with HR, behavior question.
Anonymous
//2.1 Horse racing system class Horse { public: int position; int end; Horse(): position(0){} void ready(int distance) { position = 0; end = distance; } bool move() { int go = rand() % 3; position += go; return (position >= end); } }; class Race { public: vector horses; int distance; Race(int horsesN, int inDistance) :horses(horsesN), distance(inDistance) { } void newRace() { //ready for(int i = 0; i < horses.size(); i++) { horses[i].ready(distance); cout << i << " " ; for(int j = 0; j < (distance + 4); j++) { if(j == horses[i].position) { cout << "*"; } else if(j == distance) { cout << "|"; } else { cout << "-"; } } cout << endl; } cout << endl; //go bool winner = false; int winnerIdx; int winnerEnd = 0; while(!winner) { for(int i = 0; i < horses.size(); i++) { bool finish; finish = horses[i].move(); cout << i << " " ; for(int j = 0; j < (distance + 4); j++) { if(j == horses[i].position) { cout << "*"; } else if(j == distance) { cout << "|"; } else { cout << "-"; } } cout << endl; if(finish && winnerEnd < horses[i].position) { winner = true; winnerIdx = i; winnerEnd = horses[i].position; } } cout << endl; } cout << "Winner: " << winnerIdx << endl; } };
Check out your Company Bowl for anonymous work chats.