Looking for best answer for following question
There is a function checkPassword() which takes a password and return an int which represents the number of correct characters at the correct position in that password.
Write a function findPassword() which takes a list of passwords and returns the correct password or null if it doesn't find the correct password. It can make calls to checkPassword() function but it is a very expensive function so the goal is to minimize the calls to checkPassword().
Assume all passwords are of same length.
Example:-
If correct password = abcd
calling checkPassword("axyz") would return 1
Sample Input =
String[] passwords = {"xxyz","axyz", "xbyz","abyz","axyd","xycd"}
System.out.println("password = "+findPassword(passwords));
Sample Output:-
password = abcd