Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.

You need to help them find out their common interest with the least list index sum. If there is a choice tie between answers, output all of them with no order requirement. You could assume there always exists an answer.

&nbsp;
Example 1:

Input: list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["Piatti","The Grill at Torrey Pines","Hungry Hunter Steakhouse","Shogun"]
Output: ["Shogun"]
Explanation: The only restaurant they both like is "Shogun".


Example 2:

Input: list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["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).


&nbsp;
Constraints:


	1 &lt;= list1.length, list2.length &lt;= 1000
	1 &lt;= list1[i].length, list2[i].length &lt;= 30
	list1[i] and list2[i] consist of spaces ' ' and English letters.
	All the stings of list1 are unique.
	All the stings of list2&nbsp;are unique.


class Solution:
    def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]:
        
      
        hashmap1 = {}
        hashmap2 = {}
        common = {}
        for i in range(len(list1)):
            
            hashmap1[list1[i]] = i 
            
            
        for j in range(len(list2)):
            hashmap2[list2[j]] = j 
            
     
        
        for i in hashmap1:
            
            if i in hashmap2:
                print(1)
                common[i] = hashmap1[i] + hashmap2[i]
                
        
        common = list(common.items())
        
        answer =[]
        minimum = float("inf")
        
        for  i in range(0,len(common)):
            
            if common[i][1] < minimum:
                minimum = common[i][1]
                
        for i in range(len(common)):
            
            if common[i][1] == minimum:
                answer.append(common[i][0])
        
        return answer
                
        
       
class Solution {
    public String[] findRestaurant(String[] list1, String[] list2) {
        List<String> l1 = Arrays.asList(list1);
        int least = Integer.MAX_VALUE;
        List<String> returnArray = new ArrayList<>();
        Map<String, Integer> map = new HashMap<>();

        for (int i = 0; i < list2.length; i++) {
           if (l1.contains(list2[i])) {
               map.put(list2[i], l1.indexOf(list2[i]) + i);
           }
        }
        for (Map.Entry<String, Integer> entry: map.entrySet()){ 
            if (entry.getValue() <= least) least = entry.getValue();
        }
        for (Map.Entry<String, Integer> entry: map.entrySet()){ 
            if (entry.getValue() == least) returnArray.add(entry.getKey());
        }
        
        if (returnArray.size() > 1) return returnArray.toArray(String[]::new);
        return new String[]{returnArray.get(0)};
    }
}
class Solution {
public:
    vector<string> findRestaurant(vector<string>& list1, vector<string>& list2) {
      vector<string>vc;
      unordered_map<string,int>umap,umap1;
      
      for(int i=0;i<list1.size();i++)
      {
        
        
        umap[list1[i]]=i;
        
      }
      

      for(int i=0;i<list2.size();i++)
      {
        
        
        umap1[list2[i]]=i;
        
      }
      int min=10000;
for(auto i:umap)
{
  int k=0;
  for(auto j :umap1)
  {
    
    if(i.first==j.first)
    {
      k=i.second+j.second;
      if(min>k)
      {vc.clear();
        min=k;
       vc.push_back(j.first);
      }
      else if(k==min)
      {
        vc.push_back(j.first);
      }
        
    }
  }
}
  
  
  return vc;
}
};
var findRestaurant = function(list1, list2) {
    let obj ={}
    for(let i =0; i <list1.length; i ++){
        if(list2.indexOf(list1[i]) !==-1){
            const sum = i+ list2.indexOf(list1[i])
            if(obj[sum]!==undefined)
                {
                    obj[sum]['value'].push(list1[i])
                }
            else{
                obj[sum]={}
                obj[sum]['sum']=sum
                obj[sum]['value']=[]
                obj[sum]['value'].push(list1[i])
            }

        }
    }
    return Object.values(obj)[0]['value']

};
Minimum Index Sum of Two Lists