Google 最新两道 Coding 面试题曝光!(附:英文原题 + 中文超白话解释)- 一亩三分地 – 谷歌面经

题目一(英文原题)

Input: a string with English words separated by any spaces (all validate, no guarantee on spaces)
       width: an integer -> the max number of characters per line >= 1

We wrap by words (no breaking inside a word).
Put as many words as possible (greedy).
Output: how many lines we want, an integer >= 0
A single word can be longer than the width.

✅中文解释:
给你一句英文(空格不规范也没关系)+ 一个每行最多字符数。
要求:

  • 按单词换行(不能拆单词)
  • 每行尽量塞满(贪心)
  • 返回最后需要几行
  • 单个超长单词也算一行

这题考察:贪心 + 字符串处理 + 多空格处理 + 边界判断。


✅题目二(英文原题)

Given a movie from the list, return its N similar movie with the highest rating, where N >= 1.

Each movie has a rating, and similarity is transitive:
If the process marked A similar to B, and B similar to C, then A is considered similar to C.

Example:
Movies:
"A" rating 6
"B" rating 7
"C" rating 8
"D" rating 9

Similarities:
"A" similar to "B"
"B" similar to "C"

Request 1 recommendation based on "A":
Answer = "C", which is the highest rating among all movies similar to A.

Notes:
- Rating is a float [0,10]. Invalid or missing rating = -inf.
- Need exactly N movies. If fewer exist, return [].
- movie_ratings and movie_similar are unsorted.

✅中文解释:
把所有相似电影看成一个“无向图”。输入一个电影名称,要求返回它相似电影里评分最高的 N 个。
需要:

  • 先 BFS 找到所有相似电影(同一连通块)
  • 非法评分 = -inf
  • 数量不够 N → 返回 []
  • 最终用最小堆维护 Top N

考察:BFS 图遍历 + 堆 + 边界处理。


➡️ 可以联系 CSOAHelp(我们提供高质量 OA/VO 面试辅助与全流程解析)。

Leave a Reply

Your email address will not be published. Required fields are marked *