can someone tell that why this program is always returning null array of string here.
WHY THE HELL IT ISN'T SATISFYING THE IF CONDITION?
The question is-
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.
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).
class Solution {
public String[] findRestaurant(String[] list1, String[] list2) {
int n=list1.length;
int m=list2.length;
int curr=Integer.MAX_VALUE;
String[] list3 = new String[1];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(list1[i]==list2[j]) {
if(i+j<curr){
curr=i+j;
list3[0]=list1[i];
}
}
}
}
return list3;
}
}