Google virtual on-site Questions [Reject] Dp/Game Theory? [Bay Area]
Anonymous User
630

Phone Call:
Given a n-ary Tree return max depth.

virtual on-site:

Round 1:

This is a strategy based question. straight fwd DP is not always optimal.

a = [8,2,9,4,-7,3,7,-4,8,6,2,-6,9,2]
2 Player game.
Game starts at index 0.
Player can pick a[i] or a[i]+a[i+1] or a[i]+a[i+1]+a[i+2] at each turn.
And next player can start only from index+1 where index is the last index consumed by previous player.
Both play optimally.
Return score of winning player.
Eg:
Player 1: picks elements 8,2,9 ; Total P1 Score: 19
Player 2: picks 4 ; Total P2 Score: 4
Player 1: picks -7,3,7 ; Total P1 Score: 21
Player 2: picks -4,8,6 ; Total P2 Score: 14
..
....

My Solution:
gave some DFS solution with very bad timecomplexity. Please let me know the best approach check comments thanks @lakh

Round 2:

Given a 2-D binary matrix with only either of 2 values(0,1) in each cell.
0 - free space
1 - wall

given 2 points return any minimum path btw the points.

My Solution: BFS

Round 3:

Given array of 4 letter codes( and one of the code is a secret code ) and a function called isMatching( String code ).
Return the SecretCode with minimum calls to isMatching function.
isMatching( code ) returns how many letters in code matches the SecretCode.
Eg:
Codes = [
'AXCV',
'DNCL',
'RJSL',
'WKXX',
'MXUT',
'ABCD'
]
lets say secret code is ABCD.
isMatching('AXCV') returns 2.

**My Approach: **

Codes = [
    'AXCV',
    'DNCL',
    'RJSL',
    'WKXX',
    'MXUT',
    'ABCD'
]

#my own func
def commonChars( x, code ):
    count = 0
    for i in range(4):
        if x[i]==code[i]:
            count+=1
    return count

#hidden func -- explained by interviewer -- costly call
def isMatching(code):
    x = 'ABCD'
    return commonChars( x, code )

def getSecretCode(Codes):
   
    while(Codes):
	    Tmp = []
        code = Codes.pop()
        match_count = isMatching(code)
        if match_count == 4:
            return code
        for x in Codes:
            if( commonChars( x, code ) == match_count ):
                Tmp.append(x)
        Codes = Tmp
    return None

any better approach here?

Round 4:

Given various exchange rates among different currencies.
[
[USD, INR, 74.5],
[USD, GBP, 0.72],
[INR, CNY, 0.09],
..
...
]
Write a func to Convert money from one currency to another.
**Eg: **

convert(USD,CNY,1) should return ~6.48

I did not find an efficient approach at first.
Interviewer gave a hint.. maintain mapping with common currency
USD -> any currency

He asked me to code.
This can be coded. However, I was already exhausted at this point from previous rounds and was unable to write a working code.

Thanks!

Comments (5)