Two Sigma

There are 4 sets of questions (ref: 1point3acres), All the code requires test infra.

Abstract

Normally, there would be 3 rounds interviews. First round has two questions, first question normally is easy and then the next one could be a bit difficult. Then the second round would be one median level problem and a system / OO design question, or only system / OO design. Final round is either difficult problem or a system / OO design.

Afternoon interviews would be behaviour questions mixed up with the coding, system design and brain teaser problems. I believe the goal of the afternoon interviews would be the decision from team manager, who want to know that you can be the good fit to the team, like solving problems together, discussion and etc.

This document references the posts in 1point3acres and the following docs. Thank you guys.

https://gaigai_kris.gitbooks.io/interview-basic/two_sigma.html

https://xiaoguan.gitbooks.io/prepare-for-interview/Two%20Sigma/ts-onsite-2.html

Set 1

Round 1 Calculator Class & Remove Subtree

Question 1: Calculator class (Reverse Polish Notation)

  • ไธ€ไธชCalculator็ฑป

    • ๅŒ…ๅซไธ€ไธชstackๅ’Œไธ€ไธชvector

    • ไธ€ไธช Token ็ฑป๏ผŒๅŒ…ๅซไธ€ไธชprocess(stack)ๆ–นๆณ•

    • Operand ๅ’Œ Operator ็ปงๆ‰ฟ่‡ชToken

    • Operand็š„processๆ˜ฏๅ‘stackไธญpush่ฟ™ไธชๆ•ฐๅญ—

    • OperatorๅŒ…ๅซไธ€ไธชnumOfOperand๏ผŒprocessๆ–นๆณ•ๆ˜ฏไปŽstackไธญpopๅ‡บnumOfOperandไธชๆ•ฐๅญ—ๅŽ่ฟ›่กŒๆŸ็งๆ“ไฝœ๏ผŒ็ป“ๆžœๅ†push่ฟ›stack

  • Operator (abstract base class)

    • operate(int val1, int val2)

  • Add, Subtract, Multiply, Divideๅ››ไธชclass็ปงๆ‰ฟ่ฟ™ไธชOperator base class็š„ๅ†™ๆณ•

    • pay attention to Divide

C++ code was copied from somewhere else. 
Java code was created based the c++ code, and it works. 

Design Pattern 

* Factory Pattern
  1. Follow Ups

    1. token -- operand and operator inherit from token

    2. unary and ternary operators -- add a variable of NumOperands

    3. factory design pattern

      1. Factory design pattern is a class where you can hide the creation logic of all sub-classes. Typically, it would require a type and generate an object of sub-class. Essentially, itโ€™s a mapping from types sub-classes.

    4. ๆ€Žไนˆๆ‰่ƒฝ็›ดๆŽฅ็ป™็”จๆˆทbinary, ่ฎฉไป–ไปฌๅฏไปฅ่‡ช็”ฑ็š„ๆทปๅŠ ๆ–ฐ็š„operator

      1. ๆ›ดๅฅฝ็š„ๅŠžๆณ•ๆ˜ฏๅšXML / JSON็š„serialization

  2. Key Points

    1. Abstract Class

    2. Factory Design Pattern

Question 2: Remove Subtree from Tree

  • ๅ†™ไธ€ไธชๅญๅ‡ฝๆ•ฐ๏ผŒ่ฆ็Žฐๅœบ็ผ–่ฏ‘็Žฐๅœบ่ท‘. ็ป™ๅฎšไธ€ไธชๆ•ฐ็ป„๏ผŒๆ•ฐ็ป„็š„ๆฏไธชๅ…ƒ็ด ๅฐฑๆ˜ฏไธ€ไธช่Š‚็‚น(struct node)๏ผŒๅคงๆฆ‚็š„้•ฟๅพ—ๅƒไธ‹้ข่ฟ™ๆ ท

struct node{
    int parent;
    int val;
    bool valid;
};
  • parentไปฃ่กจๅฝ“ๅ‰node็š„parent ๅœจๆ•ฐ็ป„้‡Œ็š„index๏ผŒroot node็š„parentๆ˜ฏ-1. ๆ‰€ไปฅnode ๆ˜ฏchildๆŒ‡ๅ‘parent็š„ใ€‚

  • ็ป™ๅฎšไธ€ไธชๆ•ฐ็ป„ๅ’Œๆ•ฐ็ป„็š„ๆŸไธชindex๏ผŒๅˆ ้™ค่ฟ™ไธชindexไปฅๅŠๅฎƒ็š„ๅญๆ ‘(ๅช้œ€่ฆๅฐ†node้‡Œ็š„valid็ฝฎไธบfalseๅณๅฏ)๏ผŒๅช่ƒฝ็”จO(n)็š„็ฉบ้—ดๅคๆ‚ๅบฆ

C++ was copied from somewhere else
Java was based on the C++, it works.
  1. Follow Ups

    1. Update tree size

    2. Corner cases

      1. Index is out of range

      2. delete subtree which already removed

    3. Node cannot be changed.

      1. use a boolean array to store the visited indexes.

Round 2 Blocking Queues & Slow Web Diagnose

Question 1: Blocking Queues

Because the data comes from two blocking queues, the implementation of 
non-streaming version would be two queues and call calculatePairs on different 
queue order. 

However, becasue the blocking queue could be blocked, because there is no new 
incoming data. Thus two threads would be the solution. 

C++ code is coyied from somewhere else
Java code is based on the C++ code, and it works.
  1. Follow Ups

    1. ๅฆ‚ๆžœๆœ‰ๅคšไธชqueue๏ผŒๆฏ”ๅฆ‚10ไธชqueueๆ€ŽไนˆๅŠž๏ผŒ

      1. It should use a list to store the data from each blocking queue.

      2. Lock is the same, it should lock before the calculation and release the lock afterwards.

      3. The thread input should be like (List<List<Double>> queues, int qIndex)

      4. Each thread need to maintain a list of indexes which point to the un-explored position of other queues.

      5. Every time a thread get a new data, start from the current index and find the last index suite the condition of each other queues.

Question 2: Slow Web Accessing

  1. When does it happen? How frequently ?

  2. How slower compare to the normal?

  3. Where does it happen? All places or only several places?

  4. Is there a monitor on the full stack?

    1. Host & service health check

    2. Overall host performance (CPU, Mem, I/O, Disk and etc)

    3. Time of request

    4. Time of back end request

    5. Database response time

Round 3 Wildcard Matching

https://leetcode.com/problems/wildcard-matching/solution/

The solution should start from DP solution. The testing cases should be added at beginning.

  • Step 1: Recursive Solution

  • Step 2: DP solution

  • Step 3: Backtracking

Dp solution and backtrack solution are copied from leetcode
  1. Follow Ups

    1. Better than DP? O(1) space Backtrack

Set 2

Round 1 Power of 4 & Random Iterator Dividable by 5

Question 1: Power of 4

The for loop should be trivial.
Bit mask is what interveiwer wanted. It should be explained clearly.

Question 2: Random Iterator Dividable by 5

  • Using a random number iterator to crate an iterator that only return multiply of 5

  • implement next(), hasNext(), remove()

  • Solution (the question is bit of blur so the solution is based on my understanding)

    • The class should implement Iterator<Integer>

    • add nextValue and hasNextValue to the class.

    • remove the element from the container.

Output numbers only could mod by 5.
Remove some elements from the container
Check again to make sure the elements are removed.

Round 2 Game of Life & Text Editor OO Design

Question 1: Game of Life

* 1D and 2D solution is trivial. 
    o in place solution would be prefered
    o need to ask about the boarder
* Follow ups:
    o Infinite grid
    o Large grid but alive points are sparse
    o Solve it using distribued system

Question 2: Text Editor Design

  • Design a text editor

    • insert(position)

    • delete(p1, p2)

    • highlight(p1, p2)

    • redo & undo

    • save/load

    • update

    • search

  • Data structure

    • Rope

      • Concat

      • Split

    • Highlight can be implemented by add another flag in tree node

    • Two stacks for Redo and Undo

      • Implement a class of Actions

      • Stack of Actions

    • Save & Load

      • Serialise & Deserialise tree

    • Search

      • Boyer-Moore Search

Rope data structure require two operations
1: concat
simplist solution is to create a new node: node.left = root, node.right = inputNode
Need to balance the tree after each concat
2: split
Update root to the left side and return the right side node.

Then the following operations 
* Insert(index, str)
    o inputNode = new Node(str);
    o lastNode = split(index);
    o concat(inputNode);
    o concat(lastNode);
* Delete(start, end)
    o lastNode = split(end)
    o deleteNode = split(start)
    o concat(lastNode)
* Index(index)
    o binary search
* Highlight(start, end)
    o lastNode = split(end)
    o highlightNode = split(start)
    o highlight(highlightNode)
    o concat(highlightNode)
    o concat(lastNode)
* Search
    o Iteriter inorder traverse.
    o Boyer-Moore search algorithm.

Round 3 Debug Guava

  • Source file link

  • multimap.

    • ไธ€ไธชkey ๅฏนๅบ”ไธ€ไธชcollection๏ผŒ

    • ๅ…ˆๅ†™test caseๅ†debug๏ผŒ

    • ไฝ†่ฟ™้‡Œ็‰นๅˆซๆ้†’ๅคงๅฎถ๏ผŒๅ†™functionไน‹ๅ‰็œ‹javadoc๏ผŒไธไป…ๆ˜ฏ

      • ๅผ€ๅคด้‚ฃไธ€้•ฟๆฎต

      • ๆŠŠ้ผ ๆ ‡ๆ”พmethod ๅๅญ—ไธŠๅ‡บ็Žฐ็š„้‚ฃๆฎต

    • Bugs:

      • put: not implemented

      • size:

      • clear

      • clearall

  • JUnit

    • Separate the @Test

    • Add @Begin

There are source code and the testing base.
1: implement put
2: check the bugs
3: write the tests cases

Set 3

Round 1 LRU + LFU (follow up)

Question 1 LRU

Solution key points
* DummyHead and DummyTail points to the head and tail of the double linked list
* Apply removeNode and addNode. 
    o removeNode: 
        . remove the node from the list, connect its left and right,
    o addNode:
        . Add the node to the head of the double linked list
* put(key, value)
    o check the existence of the key, update the value, update the node.
    o check size limit

protected boolean removeEldestEntry(Map.Entry eldest) {
                    return size() > CAPACITY;
                }
Solution key points
* DummyHead and DummyTail points to the head and tail of the double linked list
* Apply removeNode and addNode. 
    o removeNode: 
        . remove the node from the list, connect its left and right,
    o addNode:
        . Add the node to the head of the double linked list
* put(key, value)
    o check the existence of the key, update the value, update the node.
    o check size limit

Question 2 LFU

Data structure: three maps to keep k-v, k-count, count-list<key> and minCount
* Key-Value map
    o Stores the all the key-value
    o HashMap<T, T>
* Key-Count map
    o Store the count of the key
    o HashMap<T, Integer>
* Count-List<Key> map
    o Store the list of keys of each count
    o HashMap<Integer, LinkedHashSet<T>>
* minCount
    o keep track the min count

Round 2 Best time to buy stock & Debug median of two sorted arrays

Question 1 Best time to buy stock

Question 2 Debug median of two sorted arrays

Testing case should cover: 
* ไธคไธชๆ•ฐ็ป„้ƒฝไธบ็ฉบ
* ๆœ‰ๅ…ถไธญไธ€ไธชๆ•ฐ็ป„ไธบ็ฉบ๏ผŒๅฆๅค–ไธ€ไธชๆ•ฐ็ป„้•ฟๅบฆไธบๅฅ‡ๆ•ฐ/ๅถๆ•ฐ
* ๆ•ฐ็ป„้•ฟๅบฆ้ƒฝๆ˜ฏๅฅ‡ๆ•ฐ 
* ๆ•ฐ็ป„้•ฟๅบฆ้ƒฝๆ˜ฏๅถๆ•ฐ
* ๆ•ฐ็ป„้•ฟๅบฆไธ€ๅฅ‡ไธ€ๅถ
* index over the constraint
* overlap & non overlap

Round 3 ATM OO design

  • Design an ATM, some of the basic interfaces are already given, need to add more if necessary and then implement the class.

  • need to implement:

    • ็”จๆˆทๆณจๅ†Œ๏ผŒ็”จๆˆท็™ป้™†๏ผŒ

    • ็”Ÿๆˆๆ–ฐ้“ถ่กŒๅก๏ผŒ้ชŒ่ฏ้“ถ่กŒๅก๏ผŒ

    • ๆŸฅ่ฏขไฝ™้ข๏ผŒๅญ˜ๅ–้’ฑ็ญ‰ไธ€ๅคงๅ †ๅŠŸ่ƒฝ

  • There are

    • Accounts:

      • checking

      • saving

    • Functions:

      • withdraw

      • deposit

      • transfer

      • inquiry

      • setting

    • class

      • ATM

      • User

      • Accounts

  • Because it is a semi open-end question, there is no real correct answer. The following solution is based on my own understanding and above link.

  • It should use

    • State Pattern

    • Mediator Pattern

// Need to implement the following classes

class AccountStore
class CardHandler
class CashDispenser
class CashIntake

// Then there is a menu function in ATM class. Such as
switch (choice) {
    case LOGIN:
        //TODO: implement function to support user login
}

// ATM class has the following members

AccountStore _accountstore;   // store the account created at this ATM
CardHandler _cardhanlder;     // handles card read return
CashDispenser _cashdispenser; // handles cash withdraw
CashIntake _cashintake;       // handles cash deposit

Set 4

The questions in this set are varies. I add all questions whose frequency is higher than the others in this set. Also some of the questions from other set would also be asked in this set.

Round 1 Refrigerator

  • ๆœ‰ๅ‡ ไธชๅฎคๅ‹ไฝๅœจไธ€้—ดๆˆฟๅญ๏ผŒๆœ‰ๅฅฝ็š„ๅฎคๅ‹๏ผŒๆœ‰ๅ็š„ๅฎคๅ‹ใ€‚

  • ๅฅฝ็š„ๅฎคๅ‹ไผšไนฐไธœ่ฅฟๆ”พๅœจๅ†ฐ็ฎฑ้‡Œ๏ผŒๅ็š„ๅฎคๅ‹ไผšไปŽๅ†ฐ็ฎฑ้‡Œๆ‹ฟไธœ่ฅฟๅƒใ€‚

  • ๅ†ฐ็ฎฑ้‡Œๆœ‰ไธๅŒ็ง็ฑป็š„้ฃŸ็‰ฉ๏ผŒๆฏ”ๅฆ‚็‰›ๅฅถ๏ผŒ้ฆ™่•‰๏ผŒ้ธก่›‹็ญ‰็ญ‰ใ€‚

  • ็„ถๅŽๅœจๅ†ฐ็ฎฑ้‡Œ๏ผŒๆฏไธช็ง็ฑป้ƒฝๆœ‰ไธ€ไธชๆ•ฐ้‡ไธŠ้™๏ผŒๅฝ“็„ถไนŸไธๅฏไปฅไฝŽไบŽ0ใ€‚

  • ไป–็ป™ไฝ ไธ€ๆฎต็จ‹ๅบ๏ผŒๆจกๆ‹Ÿไนฐๅ’Œๅƒ็š„่ฟ‡็จ‹๏ผŒไนฐ้œ€่ฆไธ€ไบ›ๆ—ถ้—ด(sleep)๏ผŒๅƒไนŸ้œ€่ฆไธ€ไบ›ๆ—ถ้—ด๏ผŒ็„ถๅŽprintๅ‡บๅฎžๆ—ถ็š„ๆ•ฐ้‡ใ€‚

  • ๆฏไธชprint้‡Œ้ขไผšๆœ‰ไธชvalidation๏ผŒๅฆ‚ๆžœ่ถ…ๅ‡บไบ†ไธŠ็บฟ๏ผŒๆˆ–่€…ไฝŽไบŽ0๏ผŒๅฐฑไผšๅ‡บerror messageใ€‚

  • ไฝ ่ฆๅš็š„ๅฐฑๆ˜ฏfix่ฟ™ๆฎต็จ‹ๅบ๏ผŒ่ฎฉ็จ‹ๅบไธๅ‡บ็Žฐerror messageใ€‚

  • Solution

    • The problem is straight forward

    • We need to add locks on each element. It isn't clear what's the data structure. Here is my assumptions

      • An array to store the count of each element

      • An map to store the count of each element

    • Locks :

      • ReentrantLock

      • Semaphore: Signal, like limit the number of the thread

      • Mutex:

Possible solutions

* It is a producer - consumer model
* Lock
    o Some mates said about mutex, semaphore, sychronization and ReeentrantLock

* The code is based on my search and understanding. I left the eggLock to demo
  that when there is no lock, it may be error message.

Round 2 news feed system design

  • ๅ†…้ƒจ็ณป็ปŸไพ›ๅ‘˜ๅทฅๆŠ“ๅ–ๆƒณ่ฆ็š„ๆ–ฐ้—ป๏ผŒๆฏ”ๅฆ‚่‡ชๅทฑfacebook่ดฆๅท็š„ๆ›ดๆ–ฐ๏ผŒๆˆ–่€…ๆ˜ฏๆŠฅ็บธๆ–ฐ้—ปไธŠ็š„ๆ›ดๆ–ฐ

  • ๅ‰ๆฎตๅŽ็ซฏ็š„ๆญๅปบ๏ผŒ

    • ้กต้ข่‡ชๅŠจๅˆทๆ–ฐ็›ฎๅ‰ๆœ€ๆ–ฐ็š„topic๏ผŒ

    • ่ฟ˜ๆœ‰ไธ€ไบ›filter๏ผŒๆฏ”ๅฆ‚็ง็ฑป๏ผŒๆ—ถ้—ด๏ผŒๅ…ณ้”ฎๅญ—

    • upcoming calendar event

    • ่ฟ˜้œ€่ฆๆ”ฏๆŒๆœ็ดขๅŠŸ่ƒฝ

Because currently they are all virtual interviews. This problem may not be asked.

It should use pull and push model.

Pull model for the personal websites, like fackbook or twitter
Push model for the general websites, like wsj or nytimes

* Feed system
* Web crawler
* Search

Round 3 Super stack & String multiply

Question 1 Super stack

Here I only implements the average, min, max and mode.
Because mode is quite complex so I create another class to handle it.
It would be better to design the unit test.

Question 2 String multiply

  • Leetcode 43:

  • Key points

    • multiply a string to a digit

      • Remember to add tailing zeros

    • add two strings

* multiply a string and a digit
* add two strings
* loop on shorter string and skip zeros
* better to use StreamBuilder

Random Coding Questions

Some random questions

Statistic City Power & Temp

็ป™ไธ€ไธชcsvๆ–‡ไปถ๏ผŒๅญ˜ๆœ‰array of(ๅŸŽๅธ‚๏ผŒๆ—ฅๆœŸ๏ผŒๆธฉๅบฆ๏ผŒ็”ต็”จ้‡)ใ€‚่ฆๆฑ‚็Ÿฅ้“ๆฏไธชๅŸŽๅธ‚ๆฏๅคฉๆœ€้ซ˜ๆธฉๅบฆๅ’Œๆœ€้ซ˜็”ต็”จ้‡ใ€‚่€Œไธ”้œ€่ฆๅœจ็Ÿฅ้“ไบ†็ป“ๆžœไปฅๅŽ็ซ‹ๅˆปprint๏ผˆๆฏ”ๅฆ‚ไธ€ไธชๅŸŽๅธ‚ๅˆฐไบ†็ฌฌไบŒๅคฉ๏ผŒๅฐฑ่ฆ็ซ‹ๅˆปๆ‰“ๅฐๅ‡บไน‹ๅ‰ไธ€ๅคฉ็š„ๆ•ฐๆฎ๏ผ‰๏ผŒ่€Œไธ”้œ€่ฆๆŒ‰็…ง็Ÿฅ้“็ญ”ๆกˆ็š„้กบๅบprint๏ผˆ่ฟ™้‡Œๅ…ถๅฎžๆœ‰edge case้œ€่ฆ่€ƒ่™‘ไธ่ฟ‡trackไธ€ไธ‹่กŒๆ•ฐ็„ถๅŽๅปบไธ€ไธชqueueๅฐฑๅฅฝไบ†๏ผ‰ใ€‚ๅฎž็Žฐๅพˆ็ฎ€ๅ•๏ผŒๅปบไธ€ไธชhash table้…ไธŠไธ€ไธชqueueไน‹็ฑป็š„ๅฐฑๅฏไปฅใ€‚ๆณจๆ„ไธ€ๅฎš่ฆๅˆ ๆމไน‹ๅ‰ๅญ˜ไธ‹ๆฅ็š„cache๏ผŒๆ–‡ไปถ็‰น...ๅˆซ....ๅคง....๏ผŒ็”ต่„‘ๅ…ถๅฎžๆฒกๅคšๅฐ‘ๅ†…ๅญ˜ใ€‚้ข่ฏ•ๅฎ˜ๆœ‰็ญ”ๆกˆ๏ผŒไธŽ็ป“ๆžœdiffใ€‚

Weighted Sampling

Weighted samplingใ€‚็ป™ไธ€ไธชarray of tuple็š„๏ผˆweight, data๏ผ‰๏ผŒ่ฆๆฑ‚ไปฅ็ป™ๅฎš็š„ๆฆ‚็އsampleๆ•ฐๆฎใ€‚ ๆœ€ไผ˜็ญ”ๆกˆๆ˜ฏbinary indexd tree log(n)็š„่ฏปๅ†™complexity๏ผŒ่€Œไธ”ๆ”ฏๆŒinsert/delete๏ผŒ้ƒฝๆ˜ฏlog(n) ๆˆ‘็ป™ๅ‡บๆ™ฎ้€š็ญ”ๆกˆ๏ผŒ่ฎฐไฝๅทฒๆœ‰็š„weight็„ถๅŽๆŸฅๆ‰พใ€‚้ข่ฏ•ๅฎ˜ไนŸ่ฎคๅฏไบ†ใ€‚

Random Design Questions

Design Google Map

  • ไธป่ฆๅฎž็Žฐไธค็‚นไน‹้—ดๅ…ฌๅ…ฑไบค้€š่ทฏๅพ„ๅ’Œๆ‰€้œ€ๆ—ถ้—ดใ€‚

  • ไธป่ฆ็”จๅˆฐdijkstra's algorithmๅฎž็Žฐๆœ€็Ÿญๆญฅ่กŒ่ทฏๅพ„๏ผŒgeohashๆ‰พๆœ€่ฟ‘็š„kไธชๅทดๅฃซ็ซ™ใ€‚

  • ็™ฝๆฟimplement dijkstra'sใ€‚

  • ๅฆ‚ๆžœไธ€ๆกๅทดๅฃซ็บฟๆœ‰ๅพˆๅคš็ซ™๏ผŒๅˆ™้œ€่ฆ็”จๅˆฐbinary searchๆ‰พๅˆฐ็ฆปsourceๆœ€่ฟ‘็š„ๅทดๅฃซ็ซ™็‚นใ€‚

  • Follow up:

    • ๅทฒ็Ÿฅๆ‰€ๆœ‰่‡ช่กŒ่ฝฆ็ซ™ๅˆฐstart็‚นๅ’Œend็‚น็š„่ท็ฆป๏ผŒไฝ†ๆ˜ฏ่‡ช่กŒ่ฝฆ็ซ™ไน‹้—ด็š„ๅปบๅ›พไปฃไปท้žๅธธๅคง๏ผŒๅฆ‚ๆžœๅ‡ไฝŽๅปบๅ›พ็š„ๅคๆ‚ๅบฆ

Design Watch

  • ่ฟ™ไธชๆ‰‹่กจๆœ‰ไธ‰็งๆจกๅผ(ๆ™ฎ้€š๏ผŒๅ€’่ฎกๆ—ถ๏ผŒ็ง’่กจ่ฎกๆ—ถ)๏ผŒๅชๆœ‰ไธคไธชๆŒ‰้’ฎใ€‚

  • ๅพ—็”จ่ฟ™ไธคไธชๆŒ‰้’ฎๅฎž็Žฐๅˆ‡ๆขๆจกๅผ๏ผŒๆš‚ๅœ๏ผŒๅผ€ๅง‹ใ€‚

    • ๅ‡่ฎพไธคไธชๆŒ‰้’ฎๅˆ†ๅˆซๆ˜ฏA, Bใ€‚A๏ผŒBไธ€่ตทๆŒ‰ๅฐฑๆ˜ฏ nextMode() ใ€‚

    • ๅœจๅ€’่ฎกๆ—ถๆจกๅผไธ‹๏ผŒAๆ˜ฏๅขžๅŠ ๆ—ถ้—ด๏ผŒBๆ˜ฏๆš‚ๅœ/ๅผ€ๅง‹ใ€‚

  • Solution:

    • ็”จไธ€ไธชๅ˜้‡ๅ‚จๅญ˜็Žฐๅœจๅ€’่ฎกๆ—ถ็š„ๆ—ถ้—ด๏ผŒไธ€ไธชๅ˜้‡ๅ‚จๅญ˜็Žฐๅœจ็š„็Šถๆ€ใ€‚็„ถๅŽๆฏๆฌก call pressA() ๅฐฑ+10s๏ผŒๆฏๆฌก call pressB() ๅฐฑๅˆ‡ๆข็Šถๆ€ใ€‚

    • ๅฆ‚ๆžœ็Šถๆ€ๆ˜ฏๅผ€ๅง‹๏ผŒๅฐฑ setTimeInterval ๆฏไธ€็ง’้’Ÿ call watch.display(็Žฐๅœจๅ€’่ฎกๆ—ถ่ฟ˜ๅ‰ฉๅคšๅฐ‘)

    • ๅฆ‚ๆžœ็Šถๆ€ๆ˜ฏๆš‚ๅœๅฐฑ clear setTimeIntervalใ€‚

Design Google Doc

Distributed Services Health Check

  • ๅพˆๅคšๆœบๅ™จๅˆ†ๅธƒๅœจๅ„ไธชๅœฐๆ–น๏ผŒ่ฎพ่ฎกไธ€็ง้€šไฟกๆ–นๅผๆ˜ฏๅพ—ๅฎƒไปฌ่ƒฝ็Ÿฅ้“ๅ„่‡ช็š„health status.

  • ็ป้ข่ฏ•ๅฎ˜ๆ็คบ๏ผŒๅ„ไธชๆœบๅ™จ้œ€่ฆๆŠŠ่‡ชๅทฑ็š„"heart beat"ไผ ็ป™ๅ…ถๅฎƒๆœบๅ™จ๏ผŒๆ€Žไนˆไผ heart beatๆœ€็ฎ€ๅ•ไบ†ใ€‚

    • ๅฐฑๆ˜ฏๅ„ไธชๆœบๅ™จ้ƒฝ่‡ชๅทฑๆœ‰ไธ€ไธชoperation counter.

    • ๆฏๆฌกๆ“ไฝœoperation counter้ƒฝๅŠ 1๏ผŒ

    • ็„ถๅŽๆŠŠ่ฟ™ไธชoperation counter่ฆไผ ็ป™ๅ…ถๅฎƒๆœบๅ™จใ€‚

    • ๅ…ถๅฎƒๆœบๅ™จๅฏไปฅๆ นๆฎ่ฟ™ไธชoperation counterๆ˜ฏไธๆ˜ฏ่ฟž็ปญๅŠ ไธ€ๆฅๅˆคๆ–ญๆ˜ฏไธๆ˜ฏๆผๆŽฅๆ”ถๆŸไธชๆœบๅ™จ็š„ไฟกๆฏ

IoT data collection & store

  • ๆ˜ฏๅœจIoT็š„็Žฏๅขƒไธ‹๏ผŒๆœ‰ๅ‡ ็™พmillion็š„sensor้‡‡้›†ๆธฉๅบฆ็š„ๆ•ฐๆฎ๏ผŒๆฏไธชsensor่ฟ˜ๅˆ†cityๅ’Œtype๏ผŒ่ฆๆฑ‚่ฎพ่ฎก่ƒฝๅคŸๆ”ฏๆŒไธคไธชquery

    • ็ป™ๅฎšๆ—ถ้—ด่Œƒๅ›ดๅ†…ๆŸไธ€ไธชcityๆˆ–่€…ๆŸไธ€ไธชtype็š„ๅนณๅ‡ๆธฉๅบฆใ€‚

  • ๆœฌไบบ่ฝฌไธ“ไธš็š„็ณป็ปŸ่ฎพ่ฎกๆฏ”่พƒๆฐด๏ผŒๅคงๆฆ‚่ฏดไบ†ไธ€็•ช๏ผŒๆ„Ÿ่ง‰ๅญ˜ๅ‚จๆ–น้ขๅ…ถๅฎž็›ธๅฝ“ไบŽ้—ฎ็š„ๆ˜ฏ็ฑปไผผgoogle bigqueryๅบ•ๅฑ‚ๅคงๆฆ‚ๆ€Žไนˆๅฎž็Žฐ็š„๏ผŒ

  • ไธญ้—ดไนŸไผšfollowๅˆฐๅพˆๅคšๅ…ณไบŽๆ€Žไนˆscale็š„้—ฎ้ข˜

Board and Player

  • Design a game,

  • ๆœ‰ไธ€ไธชgrid, gridไธŠๆœ‰ไธชtarget๏ผŒๆœ‰ไธ€ไบ›players.

  • Playersไธ็Ÿฅ้“่‡ชๅทฑๅœจgridไธŠๅ“ช้‡Œ๏ผŒplayerๆœ‰่‡ชๅทฑ็š„็งปๅŠจstrategy

  • ไฝ†ๆ˜ฏ่พ“ๅ…ฅๆ˜ฏๅ‘Š่ฏ‰ไฝ ไธŠๆฌก็š„็งปๅŠจๆ˜ฏๆŽฅ่ฟ‘targetไบ†่ฟ˜ๆ˜ฏ่ฟœ็ฆปtargetไบ†ใ€‚

    • ไบ›ๆ˜ฏSmartPlayer๏ผŒไป–ไผšๆ นๆฎ่พ“ๅ…ฅๅ†ณๅฎšไธ‹ไธ€ๆญฅๆ€Žไนˆ่ตฐ

    • ๆœ‰ไบ›ๆ˜ฏRandomPlayer๏ผŒไป–ไปฌๅฐฑๆ˜ฏ้šๆœบ่ตฐ

* Game
    o Game class should have a board and some player
    o it should control when start and end
* Board
    o Board should record the players location.
    o interfaces:
        . registerPlayer(Player)
        . int isCloser(Player, Move)
* Player
    o Player should only record the result from prev move, for decision
    o interfaces:
        . int[] nextMove();
        . setResult(int)

Stock subscription notification system

  • It should be like the message queue subscription model.

  • It feels like the new feed system

Random Brain Teaser Questions

Question 1:

  • ๅฐฑๆ˜ฏไธ€ไธชtrainๅœจๅ…ฅ็ซ™ๅฐๅ’Œๅ‡บ็ซ™ๅฐ็š„ๆ—ถๅ€™้œ€่ฆๅ…ˆๅ‡้€Ÿๅ†ๅŠ ้€Ÿ๏ผŒ้—ฎไฝ ่ฝฆ็š„ๅ“ชไธช้ƒจไฝๅœจๆ•ดไธช็ซ™ๅฐๅœ็•™็š„ๆ—ถ้—ดๆœ€้•ฟใ€‚

    • ๆˆ‘ๅคงๆฆ‚ๆ€่€ƒไบ†ไธ€ไธ‹ไนฑ่ฏดไบ†ไธ€ไธชheadโ€ฆโ€ฆๅŽๆฅwork out math็š„ๆ—ถๅ€™ๆˆ‘ๅ‘็Žฐheadๅ’Œtail็š„ๆ—ถ้—ดๆ˜ฏ็›ธๅŒ็š„๏ผŒๆˆ‘ๅฐฑๅผ€ๅง‹่ง‰ๅพ—ๅบ”่ฏฅๆ˜ฏmidwayๅœ็•™็š„ๆ—ถ้—ดๆœ€้•ฟ๏ผŒ(่ฟ™ไธชๆ—ถๅ€™ๆœ‰ไธ€ไธชๅ‡่ฎพๆ˜ฏๅ‡้€Ÿๅ’ŒๅŠ ้€Ÿ็š„ๅŠ ้€Ÿๅบฆๆ˜ฏ็›ธๅŒ็š„)ใ€‚

    • ้ข่ฏ•ๅฎ˜่ฏดๅฏน๏ผŒ็„ถๅŽๅฐฑ้—ฎhow much longer? ็„ถๅŽ็ป™ไบ†ไธ€ไธชๆ็คบ็”จs = 1/2 a t t่ฟ™ไธชๅ…ฌๅผๅŽปๆŽจ๏ผŒๆˆ‘ๅคงๆฆ‚ๅ†™ไบ†ๅ‡ ่กŒ่ทŸไป–่ฏดๅคงๆฆ‚ๆ˜ฏ(sqrt{2} - 1) longer๏ผŒไป–ๆœ‰็‚นๆƒŠ่ฎถๅ› ไธบไป–ๅฅฝๅƒ่ง‰ๅพ—ๆˆ‘ๅพˆๅคšๆญฅ้ชค่ทณๆމไบ†โ€ฆโ€ฆanywayไป–่ง‰ๅพ—ๆฒก้—ฎ้ข˜๏ผŒๅŽๆฅๅˆ้—ฎๅฆ‚ๆžœๅ‡้€Ÿๅ’ŒๅŠ ้€Ÿ็š„ๅŠ ้€ŸๅบฆไธๅŒ้‚ฃๆ€ŽไนˆๅŠž๏ผŒๅ“ชไธช็‚นๅœ็•™็š„ๆ—ถ้—ดๆœ€้•ฟ๏ผŸๆˆ‘็›ดๆŽฅ็”ปไบ†ไธคไธ‹็Œœไบ†ไธ€ไธช่กจ่พพๅผๅคงๆฆ‚ๅฐฑ่ฏดๆ˜ฏ่ฆๅœจ่ฝฆ็š„(a2 / (a1 + a2))ๅˆ†็•Œ็š„ๅœฐๆ–นโ€ฆโ€ฆ้ข่ฏ•ๅฎ˜ๅฐฑ้—ฎไธบๅ•ฅ๏ผŸๆˆ‘ๅฐ่ฏ•work out mathไบ†ๅŠๅคฉๆœชๆžœ๏ผŒๅๆญฃๅคงๆฆ‚ๅฐฑๆ˜ฏ1/2 a1 t1 t1 = x, 1/2 a2 t2 *t2 = S - x็„ถๅŽๅŽปmaximize t1 + t2็š„ๅ€ผ๏ผŒๅพˆๆ˜Žๆ˜พ็š„ๆˆ‘็š„ๆ•ฐๅญฆๆฐดๅนณๅทฒ็„ถไธ่ถณไปฅ่งฃๅ†ณ่ฟ™ไธช้—ฎ้ข˜ไบ†โ€ฆโ€ฆ

    • ไธ่ฟ‡้ข่ฏ•ๅฎ˜่ฏดๆˆ‘ๅพˆๆƒŠ่ฎถไฝ ไธ€ๅผ€ๅง‹็ป™็š„็ญ”ๆกˆๅฐฑๆ˜ฏๅฏน็š„๏ผŒๆˆ‘ๅฐฑ่ฏด่ฟ™ไธชintuitivelyๅคงๆฆ‚ๅฐฑๆ˜ฏ่ฟ™ๆ ทblah blah๏ผŒ็„ถๅŽไป–่ฏดไธ็”จๆŽจไบ†ๆˆ‘ไปฌๅˆๅผ€ๅฟƒ็š„่Šไบ†ไธ€ไบ›culture้—ฎ้ข˜็ป“ๆŸ

Last updated

Was this helpful?