Trains the technique from
LeetCode 721Accounts MergeThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Every gate at a depot keeps its own badge log, so one crew member can show up in several logs. You are handed records, where records[i] starts with the crew member's display name and continues with the badge codes that were scanned under that name at one gate.
Badge codes identify a person: if two records list a code in common, they were written by the same crew member. Follow that through as far as it goes, so records linked by a chain of shared codes are all the same person even when no single code is in all of them. One crew member always signs with one display name, though it is quite possible for two unrelated crew members to sign with the very same one, so the display name on its own tells you nothing.
Return one entry per crew member: the display name, followed by that person's badge codes with duplicates removed and sorted in increasing lexicographic order. The entries themselves may come back in any order.
Example 1
The first and third records share qp2, so they came from one crew member. The fourth shares nothing with them and belongs to a different crew member who happens to sign the same way.
Example 2
The first two records look unrelated until the third links p2 to p3, which pulls all three into one crew member.
Example 3
A single record still has to come back with its codes in increasing order.
The values you return may be in any order.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def merge_badge_records(records: list[list[str]]) -> list[list[str]]:public List<List<String>> mergeBadgeRecords(List<List<String>> records)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.