Leetcode Problem 599. Minimum Index Sum of Two Lists

599. Minimum Index Sum of Two Lists

Leetcode Solutions

Approach # Using HashMap (linear)

  1. Initialize a HashMap indexMap to store strings from list1 with their indices.
  2. Iterate through list1 and populate indexMap with each string and its index.
  3. Initialize variables minSum to a large number and result as an empty list.
  4. Iterate through list2, for each string: a. Check if indexMap contains the string. b. If it does, calculate the index sum. c. If the index sum is less than minSum, update minSum and reset result with the current string. d. If the index sum equals minSum, append the current string to result.
  5. Return the result list.
UML Thumbnail

Approach # Without Using HashMap

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...