classSolution{ fun findRestaurant(list1: Array<String>, list2: Array<String>): Array<String> { val map1: HashMap<String, Int> = hashMapOf() val res = mutableListOf<String>() var minIndex = 10001; for (i in list1.indices) { map1[list1[i]] = i } for (i in list2.indices) { if (map1[list2[i]] != null && i + map1[list2[i]]!! <= minIndex) { minIndex = i + map1[list2[i]]!! } } for (i in list2.indices) { if (map1[list2[i]] != null && i + map1[list2[i]]!! <= minIndex) { res.add(list2[i]) } } return res.toTypedArray() } }