Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
failure scenario

anuraagkiran555

Aug 2, 2024

Correct me if I'm wrong but consider this scenario.

["a", "c", "d", "b", "a", "f", "g", "h", "b"]

shortest distance would be returned as 4 instead of 1

0

0

Comments
Comments
V K
V Ka year ago

Considering a, b in the given array. Check needs to be placed to updated the positions only if with the current index, it is only less than the previous distance. Or else it should not be updated.

FirstWord = 0

SecondWord = 3

——

FirstWord = 4 —> Updated here becau...