刚帮一位学员做完 26 Google SWE Intern OA 的面试,题型依然是两道 coding,难度跟 TikTok 有点差别,Google 的难度提升了一点,两道题都是 medium 往上,以前更偏常规的数据结构题,今年更强调 graph algprithm 与变形题,把这次 OA 的题目分享给想投 Google 的同学做个参考~,一起看看吧。
第一题 Dynamic Programming
Problem 1 :
Given a string s, return the number of palindromic substrings in it. A string is a palindrome when it reads the same backward as forward.
解题思路: 可以使用中心扩展法或者动态规划。中心扩展法的思路是以每个字符(或两个字符之间)为中心,向两边扩展检查回文。动态规划的思路是用 dp[i][j] 表示从位置i到位置j的子串是否为回文。中心扩展法的时间复杂度是 0(n2) ,空间复杂度是 0(1) ,相对更优。
Problem 2 :
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. How many distinct ways can you climb to the top?
解题思路: 这是经典的爬楼梯问题,dp[i] 表示到达第i步的方法数。递推关系是 dp[i]=dp[i-1] + dp[i-2] .
基本情况是是 dp[0]=1,dp[1]=1。可以用 bottom-up approach,也可以优化 space complexity 只用两个variables 。但 Google 的版本通常会有变化,比如可以爬1、2、3步,或者某些步数不能踩。
第二题 Tree and Graph
Problem 3 :
Given the root of a binary tree, return the aximum path sum of any non-empty path. A path is defined as a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them.
解题思路: 使用递归的思想。对于每个节点,计算以该节点为根的子树能够提供的最大路径和。需要考虑四种情况:只包含当前节点、当前节点加左子树、当前节点加右子树、当前节点加左右子树。这道题的关键点是要区分两个概念:以当前节点为根向下的最大路径和(可以返回给父节点),以及经过当前节点的最大路径和。
Problem 4 :
There are a total of numCourses courses you have to take, labeled from o to numCourses- 1. You are given an array prerequisites where prerequisites[i] = [ai, bil indicates that you must take course bi first iï you want to take course ai. Return true if you can finish all courses. Otherwise, return false.
解题思路: 这是 Course Schedule 问题,本质上是检测有向图中是否存在环。使用拓扑排序或者 DFS 检测环。拓扑排序的方法是维护每个节点的入度,每次移除入度为0的节点,如果最终能移除所有节点则无环。DFS 方法是使用三种状态标记节点:未访问、正在访问、已访问,如果在 DFS 过程中遇到正在访问的节点则存在环。
总结
- Google SWE Intern OA 的题目特点是不追求刁钻的难题,注重问题拆解的能力,题目一般是 medium到 hard 级别。
- 准备 Google SWE Intern OA 要多刷 LeetCode,特别是 Google tag 的题目,进行现实练习,mock OA,练习在时间压力下快速写出 bug-free 的代码。
害怕 Google SWE Intern OA 过不了?
这位学员之所以能高效通关,拿到面试 offer,正是因为 Programhelp 的实时语音助攻,在他们思路卡壳的瞬间,精准介入——不是直接给出答案,而是引导他们自己构建出清晰、健壮、符合 Google 标准的代码逻辑。
如果你也在瞄准 Google、Meta、Apple等顶尖公司的SWE实习机会,Programhelp 为你提供专业的远程语音助攻、OA代写、mock interview 陪练,确保你的技术深度,能在高压的OA环境中,100%地转化为令人信服的面试表现!