← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given a list of company relationships where each relationship is represented as a string "A B" meaning company A is the parent of company B. No cycles exist, and every company appears at most once as a child. Implement a function that, for any query company, returns the name of its topmost parent (the root of its tree). If the query company itself has no parent, return its own name. The function will be called many times, so optimize for speed.