64. Minimum Index Sum of Two Lists

Find the common restaurants with the minimum index sum in two lists.
Example 1
Input: list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["KFC","Shogun","Burger King"]
Output: ["Shogun"]
Explanation: Shogun has an index sum of 1, which is less than KFC and Burger King.
Example 2
Input: list1 = ["happy","sad","good"], list2 = ["sad","happy","good"]
Output: ["sad","happy"]
Explanation: Both sad and happy have the same minimum index sum of 1.
Example 3
Input: list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["Piatti","The Grill at Torrey Pines","Hungry Hunter Steakhouse","Shogun"]
Output: ["Shogun"]
Explanation: Shogun is the common restaurant with the minimum sum of indices.
hash tablemediumstrings
JavaScript
Loading...
Line 1, Char 1