LinkedIn Interview question for Senior Software Engineer

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-12-09Added By Anonymous
Source: Link

Given a list of words {"java", "c++", "c#","git","java"}.

The function takes 2 words that always belong to the list. Find the minimum distance between the words in terms of postition.


Eg input->java,git

java found at indices 0,4

git at 3

so minimum distance is (4-3=1) and NOT (3-0=0)


I could not come up with optimal solution. Hence could not clear.

Comments