Verily Phone Screen Interview

That is a sad story…

Just several days ago, I received an email from Verily, an Alphabet company which delicates in life science. Their HR passed my application and going to move me to the phone interview. However, I messed it up…

I have to say that interview is not a difficult one. The question is like a medium level question at Leetcode:

Given a 1-dimensional axis, a man can move left or right in each time unit. How many possibilities that the man stands on x point after t time units?

I stupidly tried DP at first and struggled in how to implement the state transform formula, that wastes a lot of time.

Today, I reviewed this question and found a fairly easy solution. We do not even need Dynamic Programming.

l + r = t   (1)
r - l = x   (2)

Once we solve this equation, we can directly calculate the number of combinations. For example, the total possibilities of that man stand on point 5 after 9 time units is C72 = 21.

Validate IP address

昨天面试了微软北京的组,Coding问了一道判断IP是否合法的问题,然鹅当时脑子打铁,写的完全惨不忍睹,今天早上起床吓得我赶紧重新写了一遍。

class Solution(object):
    def isIPv4(self, s):
            try: 
                return str(int(s)) == s and 0 <= int(s) <= 255
            except: 
                return False
            
    def isIPv6(self, s):
        if len(s) > 4: 
            return False
        try: 
            return int(s, 16) >= 0 and s[0] != '-'
        except: 
            return False

    def validIPAddress(self, IP):
        """
        :type IP: str
        :rtype: str
        """
        if IP.count(".") == 3 and all(self.isIPv4(i) for i in IP.split(".")): 
            return "IPv4"
        if IP.count(":") == 7 and all(self.isIPv6(i) for i in IP.split(":")): 
            return "IPv6"
        return "Neither"