注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
本帖最后由 匿名 于 2026-1-21 13:24 编辑
首先声明:本文是AI根据我写的草稿生成的
先说结论:我挂了。挂完的第一反应是“我是不是真的挂得有点委屈?”于是把整个过程写详细一些,代码、思路、沟通、踩坑,都摊开给大家看,欢迎拍砖。
---
## TPS(Technical Problem Solving)轮:题目澄清反复、时间不够用
- 时长:~60min
- 结果:挂
- 反馈:Need to collaborate more(多协作)
### 题目(我理解的版本在变化)
netlifx home page has a list of shelf,每个 shelf 有一堆 title。要在 viewport(每个 shelf 最多显示 X 个)里做dedupe。垂直滚动我们先不管(vertical viewport 视为无限)。
### 我的推进过程(v1 → v5)
#### v1:全局去重(拿到口头确认后开写)
当时我问了不少问题,面试官说 OK,我就开始写。结果写完发现他要的不是这个……
```python
def dedupe_v1(titles: list[list[int]], x: int):
visited = set()
ret = []
for shelf in titles:
current = []
for title in shelf:
if title not in visited:
current.append(title)
visited.add(title)
ret.append(current)
return ret
```
#### v2:只在前 X 个 unique 里全局去重(还是不对)
```python
def dedupe_v2(titles: list[list[int]], x: int):
visited = set()
ret = []
for shelf in titles:
current = []
for title in shelf:
if len(visited) <= x and title not in visited:
current.append(title)
visited.add(title)
elif len(visited) > x:
current.append(title)
ret.append(current)
return ret
```
#### v3:前 X 位跨 shelf 去重,之后只在各自 shelf 内去重(思路对,但实现有坑)
```python
def dedupe_v3(titles: list[list[int]], x: int):
visited = set()
ret = []
for shelf in titles:
current = []
local = set()
for title in shelf:
if len(current) < x:
if title not in visited:
current.append(title)
eft + 1 > len(ret):
ret = shows[left:right + 1]
return ret
```
最优的跳指针(post-interview by AI):
```python
def max_consecutive_unique_shows_optimal(shows: list[int]) -> list[int]:
left = 0
ret = []
visited = dict()
for right in range(len(shows)):
cur = shows[right]
if cur in visited and visited[cur] >= left:
left = visited[cur] + 1
visited[cur] = right
if right - left + 1 > len(ret):
ret = shows[left:right + 1]
return ret
```
### 我的反思(Coding)
- 我选择了能保证正确性的 dictionary 版本,确实不如 set 简洁;在压力下优先稳是本能,但从“代码美感/简洁性”的角度不加分。
- 面试问“还能不能更好”,我应该把 set 版也写出来(即使晚几分钟),或者先用口头把 set 的思路讲清楚再动手。
---
## 我觉得可能委屈的点 & 想请大家评价
- TPS 我确实有问、有确认,但仍然多次误解;是不是应该用更强的“Example oriented clarification”来合作(collaborate)?
- Coding 第二题我在时间压力下交付了正确、O(n)、可读的解,但不够“clean”;这种情况下该不该挂?
- 如果你是面试官,你会怎么打分? 是不是Netflix bar很高? |