Amazon VO 面试真题解析:字符串压缩/解压系统设计,Normalization、Persistence 与 Async Processing

17次阅读
没有评论

Design a String Compress(string input) system.

The system should support compressing an input string and later decompressing it back to the original form.

Example 1

Input 1: "This is soooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo good"
Output 1: "This is s12o g18od"

Example 2

Input 2: "this"

Discussion

What will be the output?

A: You need to define it so that Decompress can decode and decompress it back.

这道题本质上是在设计一个可压缩、可解压的字符串处理系统,不只是做简单的字符替换,还要保证压缩后的结果能够被反向还原。题目图里强调了整体流程:UI 经过 Authentication 后,进入 validation,再做 normalization、persistence,并把部分工作交给 async processing,同时数据会落到 S3 和 PostgreSQL/Aurora 之类的存储中。解题时要先统一输入格式,再定义一种明确且无歧义的编码方式,例如对连续重复字符做 run-length 压缩,并确保解压时能准确恢复原串。核心关注点是字符串编码规则、可逆性、以及在系统设计中如何把校验、归一化、持久化和异步处理拆开。

正文完
 0