刚帮一位学员做完 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 inthe 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%地轉化為令人信服的面試表現!