LinkedIn | Phone screen

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2021-10-27Added By Anonymous
Source: Link

I was asked this question in the phone screen

given an input in the form e->b, c->a, b->a (which repesents that the first character is of smaller value than the second one) and a string, find out if the string is sorted based on the input list.

for input string "ecba", output is true as 'b' should be lying after 'e' and 'a' should be lying after 'c' and 'b'.

for input string "abce", output is false as 'a' should be after 'c' and 'b'.

I solved this using topological sort, got rejected :/

Can someone help with a better approach

Comments