记微软面试

我是三月份就做好笔试,由于个人时间问题顺延了,但好像给我标漏了
不管怎样,终于赶上了最后的补录面试。本人作为一只菜鸡做好了两战的准备吧。(实习和秋招
----------------------------分割线------------------------------------------
2021/6/7 11:00-11:45
first round
全程英文面,面试官英语超流利
个人介绍
介绍一个自己的项目以及项目的难点(业务的东西没有深问
编程:给定一个整型数组,找出和为正数的子数组个数。
就首先想到的就是暴力了呗,时间复杂度为O( n 2 n^2 n2),空间复杂度为O(1)

# input: 1 -2 3 -2 
def PSI(nums):
    if not nums: return 0
    window = 0
    res = 0
    for i in range(len(nums)):
        window = nums[i]
        if(window>0): res += 1
        for j in range(i+1,len(nums)):
            window += nums[j]
            if(window>0): res += 1
    return res

print(PSI([1,-2,3,-2]))
print(PSI([-2]))
print(PSI([1,3,4]))
print(PSI([-4763,-43,2448,7609,-5697,721,-1524,582,-1236,4797]))
print(PSI([-1644,-5339,8838,1295,-6961,6367,-6996,7299,8166,-6596,5704,-3379,-1017, -8521, 6888 ,-3618, -7607, 2520, 516, 6240]))

然后面试官提示还有nlogn的解法,我说是排序的做法吗,面试官又提示分治的关键字,merge还是quick sort,难道是quick sort,因为这个题是求子数组所以是连续的,不知为啥我就联系到partition了,面试官说merge,好吧,反正最后我还是想不到怎么用merge。面试后google了一下。
Counting number of contiguous subarrays with positive sum in O(nlogn) using O(n) transformation
Counting inversions in an array
上述两个链接思路就完全出来了:在merge sort过程中保存翻转的个数。我觉得挺巧妙的。
----------------------------分割线------------------------------------------
2021/6/7 14:00-14:45
second round
基本全程英文面,除了不太好表述的用了几句中文
leetcode原题:设计贪吃蛇
这种模拟过程的题目,首先要选好数据结构,其次一定要逻辑清晰
这里self.snake可以用list,也可以用dequeue优化,因为尾部需要进出,头部需要进。

class SnakeGame:

    def __init__(self, width: int, height: int, food: List[List[int]]):
        """
        Initialize your data structure here.
        @param width - screen width
        @param height - screen height 
        @param food - A list of food positions
        E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].
        """
        self.height = height    #行数
        self.width = width      #列数
        self.food = food
        self.snake = [ [0,0] ]    #起点,初始化
        self.score = 0
        

    def move(self, direction: str) -> int:
        """
        Moves the snake.
        @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down 
        @return The game's score after the move. Return -1 if game over. 
        Game over when snake crosses the screen boundary or bites its body.
        """
        nxt_head = self.snake[0][:]   
        # tail = self.snake.pop(-1)   #此时先按照蛇往前走了一步,还没吃东西
        tail = self.snake.pop(-1)
        if direction == "U":
            nxt_head[0] -= 1
        elif direction == "D":
            nxt_head[0] += 1
        elif direction == "L":
            nxt_head[1] -= 1
        else:
            nxt_head[1] += 1

        if nxt_head in self.snake:  #头的下一步咬到自己身子了,咬死了
            return -1
        if not (0 <= nxt_head[0] < self.height and 0 <= nxt_head[1] < self.width):
            return -1       #超界了
        
        self.snake = [nxt_head] + self.snake    #新蛇头,头插
        
        if self.food and nxt_head == self.food[0]:
            self.score += 1
            self.food.pop(0)
            self.snake.append(tail) #蛇头吃到东西了,蛇尾不应该删除,再加回来

        return self.score
        


# Your SnakeGame object will be instantiated and called as such:
# obj = SnakeGame(width, height, food)
# param_1 = obj.move(direction)

这一面表现的不是很好,一个月没刷题了,这个题没做过一上来就有点慌乱,后面感觉自己越来越不自信。但是这轮面试给了我激励,刷题不能松懈,细水长流保持手感。我觉得平时的稳扎稳打很重要,临危不乱即使遇到没见过的也能冷静分析,其实面试官是一直在引导你的。还有就是保持谨慎和解题热情。

----------------------------分割线------------------------------------------

June 10, 2021, 11:00 - 11:45
leader round
全程英文面
三个模块 coding+项目介绍+提问题
啊仍然是lc原题dp类困难题 石子游戏
我有大概思路但coding细节也是面试官一步步提意见完善,感谢
其实代码超简单,或许这就是dp的魅力吧

def winnerSquareGame(self, n: int) -> bool:
        if n==0: return False
        if n==1: return True
        if n==2: return False
        dp = [False]*(n+1)
        dp[0] = False
        dp[1] = True
        dp[2] = False
        for i in range(3,n+1):
            j = 1
            while j*j<=i:
            # for j in range(1,math.floor(n**0.5)+1):
                dp[i] =  not dp[i-j*j] 
                if dp[i] == True:
                    break
                j+=1
        # print(dp)
        return dp[n]

不管结果怎样,微软的面试体验特别好,不像国内大厂那种
----------------------------分割线------------------------------------------
上岸了,实习offer get

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值