I am a novice in solving DSA problems. I am stuck to start an approach to this problem. Can someone please provide me help or reference to this problem?
Question
N people are standing in a queue based on descending order of their age, find the last person's name with the given age K. If not found, return "Not found".
Input Format
First line contains two integers N, K - Number of people, the given age.
Second line contains N integers - The ages of people.
Third line contains N strings - The names of people.
Output Format
- Print the name of the last person with the given age or "Not found" if not present.
Sample Input
6 30
80 30 30 7 3 3
Sam Will Roy Lane Pam Jim
Sample Output
Roy
Explanation
- The people with age 30 in order are Will, Roy. The last person from them is "Roy".
Constraints
1 <= N <= 10^5
1 <= K, Age[i] <= 10^5
1 <= |Person's name| <= 10
Here is my code:
import java.util.*;
class FindLastPersonOfAgeK{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
List<Integer> ages = new ArrayList<Integer>();
List<String> people = new ArrayList<String>();
for (int i = 0; i < n; i++) {
ages.add(sc.nextInt());
}
for (int i = 0; i < n; i++) {
people.add(sc.next());
}
String ans = findLastPersonOfAgeK(ages, people, k);
System.out.println(ans);
sc.close();
}
static String findLastPersonOfAgeK(List<Integer> ages, List<String> people, int k){
}
}