Akuna OA — “Not Hard, Just Don’t Mess Up
programhelp.net·12h·
Discuss: DEV
Flag this post

这次 11.18 的 Akuna OA ,我们这边带的几位同学整体反馈都比较一致:题目不难,但写得是否干净利落,差距一下就拉开了。Akuna 本身对代码质量、思路完整性非常敏感,所以这份解析我们按真实做题体验做了复盘,希望能给后来人一个更清晰的参考。

Problem 1 — Find the shortest lexicographically smallest substring containing k ‘I’

Given a string s and an integer k, return the shortest substring of s that contains at least k occurrences of the character 'I'. If multiple substrings have the same shortest length, return the lexicographically smallest one.

这题属于典型的“不要想复杂,直接写就行”的类型。

题意摘要: 给你字符串 s 和整数 k,要找一个 substring,里面至少/恰好含 k 个 ‘I’。 在所有满足条件的子串里:

先比长度(越短越好)

长度相同再比字典序

我们建议的稳定思路:

外层 loop 枚举每个起点 i

里层往后扫,直到凑够 k 个 ‘I’

只要满足条件就把当前 substring 记下来

最后对所有 substring 排序: length → lexicographical order

这种写法易写、易 debug,也方便在压力环境下快速 AC。

Problem 2 — Compute accumulat…

Similar Posts

Loading similar posts...