回复: 0
跳转到指定楼层
上一主题 下一主题
收起左侧

【求米】Stripe 2025 SWE Intern OA分享(含笔记)

全局:

2025(10-12月) 码农类General 本科 实习@stripe - 网上海投 - 在线笔试  | 😐 Neutral 😣 Hard | Other | 应届毕业生
本帖最后由 EleanorLiu 于 2025-11-11 12:28 编辑

OA原题+Mark down笔记;求加米,谢谢!

# Stripe “route_requests” — Load-balancing WebSocket Connections

Implement a function to simulate a load balancer that routes long‑lived websocket **CONNECT** requests to one of several Jupyter target servers. You must also handle **DISCONNECT** events, per‑server **capacity limits**, and **SHUTDOWN** events that temporarily evict and re‑route existing connections.

---

## Function Signature (Java)

```java
List<String> route_request(
    int numTargets,
    int maxConnectionsPerTarget,
    List<String> requests
)
```
- `numTargets`: number of target Jupyter servers. Targets are **1‑based**.
- `maxConnectionsPerTarget`: per‑server capacity. (Used in Part 4. If very large, assume “no limit”.)
- `requests`: sequence of input lines in order received.

---

## Request Line Schemas

1. `action,connectionId,userId,objectId` — used for `CONNECT` and `DISCONNECT`  
2. `action,targetIndex` — used for `SHUTDOWN` (with 1‑based `targetIndex`)

- `action ∈ { CONNECT, DISCONNECT, SHUTDOWN }`

---

## Return Value (Log)

Return a list of strings, **one for every successful connection** (initial routes and any re‑routes after shutdowns), formatted as:

```
connectionId,userId,targetIndex
```

Rejected connections are **not** logged.

---

## Rules by Part

### Part 1 — Basic Load Balancing (tests 1–4)
- On each `CONNECT`, choose the target with the **fewest active connections**.
- Break ties by **smaller target index**.
- Routing is based only on the events seen so far (order matters).

### Part 2 — Disconnections (tests 5–8)
- On `DISCONNECT, connectionId, ...`, remove that active connection from its target.  
  (You may assume the `connectionId` is valid and active.)

### Part 3 — Object Affinity (tests 9–11)
- If any active connection exists for an `objectId`, **all new connections** with that same `objectId` **must connect to the same target** (the “pinned” server), even if that is not the least‑loaded option.
- If no active connection exists for the object, route normally per Part 1.
- The user ID does **not** affect routing—only the object ID creates affinity.
- When the last connection for an object ends, the affinity disappears.

### Part 4 — Target Capacity (tests 12–14)
- Each target has a max of `maxConnectionsPerTarget` active connections.
- When routing, **exclude** targets that are **at capacity**.
- If an object is pinned to a target that is **full**, the new `CONNECT` is **rejected** (no log).
- If all eligible targets are full, the `CONNECT` is **rejected**.

### Part 5 — Target Shutdown (tests 15–17)
- `SHUTDOWN,targetIndex` makes that target **temporarily unavailable** and **evicts all its active connections**.
- Evicted connections must be **re‑routed in ascending `connectionId` order** using the same rules (least load → tie by index; object affinity; capacity). The shutting‑down target is **not eligible** while down.
- **Log** each successful
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
ing[]::new);
            String action = parts[0];

            if ("CONNECT".equals(action)) {
                // CONNECT, connectionId, userId, objectId
                Conn c = new Conn(parts[1], parts[2], parts[3], -1);
                int t = choose.apply(c);
                if (t != -1) attach.accept(c, t); // rejected connects are not logged
            }
            else if ("DISCONNECT".equals(action)) {
                // DISCONNECT, connectionId, userId, objectId
                Conn c = byConnId.get(parts[1]);
                if (c != null) detach.accept(c);  // guaranteed valid per prompt
            }
            else if ("SHUTDOWN".equals(action)) {
                // SHUTDOWN, targetIndex
                int down = Integer.parseInt(parts[1]);

                // 1) Mark as unavailable so it's excluded from routing decisions.
                available[down] = false;

                // 2) Evict all connections from this target in connectionId order.
                List<Conn> evicted = new ArrayList<>(targetConns.get(down).values());

                // 3) Remove them first to clear loads / object affinities.
                for (Conn c : evicted) detach.accept(c);

                // 4) Re-route evicted connections using the same rules.
                for (Conn c : evicted) {
                    int t = choose.apply(c);
                    if (t != -1) attach.accept(c, t); // only successful re-routes are logged
                }

                // 5) Target immediately becomes available again after shutdown completes.
                available[down] = true;
            }
        }

        return log;
    }
}
```

本帖子中包含更多资源

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x

评分

参与人数 1大米 +20 收起 理由
匿名用户-C3G4G + 20 欢迎分享你知道的情况,会给更多大米奖励!

查看全部评分


上一篇:Google SWE 26ng 第一轮VO面经
下一篇:求近期meta de要vo的小伙伴一起mock
您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表