Minimum Index Sum of Two Lists
Input:
["Shogun", "Tapioca Express", "Burger King", "KFC"]
["Piatti", "The Grill at Torrey Pines", "Hungry Hunter Steakhouse", "Shogun"]
Output:
["Shogun"]
Explanation:
The only restaurant they both like is "Shogun".Input:
["Shogun", "Tapioca Express", "Burger King", "KFC"]
["KFC", "Shogun", "Burger King"]
Output:
["Shogun"]
Explanation:
The restaurant they both like and have the least index sum is "Shogun" with index sum 1 (0+1).Solution
HashMap - Time: O(n1 + n2), Space - O(n1 * x)
HashMap - Time: O(n1 + n2), Space Optimized: O(min(n1, n2) * x)
Reference
Last updated