← 返回 uber 的题目列表Compare Two Structs / Classes for Equality
类型:qbank
Onsite coding prompt: write a simple implementation to compare two structs / classes and decide whether they are identical. The source gives only the high-level task, so clarify field traversal, nested objects, arrays, nulls, and custom equality rules before coding.
Requirements
Input: two struct / class instances.
Output whether the two objects should be considered identical.
Clarify the equality contract before implementing: compare by value versus identity, which fields count, and how nested objects are handled.
Clarify collection fields, nullable fields, floating-point fields, and cycles if the language / object model allows references.
Notes
The prompt was described only at a high level, so the interview value is in requirements clarification and robust test coverage.
Treat this as a practical coding exercise, not a LeetCode-style algorithm puzzle.
Preparation
Practice implementing deep equality for nested dictionaries / objects with lists and scalar values.
Prepare tests for missing fields, reordered fields, nested objects, null, and repeated references.
Be ready to state when the implementation intentionally uses shallow equality.