You and your friends have viewed and rated several movies during past few weeks. "The CoderMan" is a new movie which is on this week and you want to know whether it's worth watching it.
You will be given a String yourEvaluations, containing your evaluations for all movies. The ith character of yourEvaluations will correspond to the ith movie and will be either a digit or 'X'. 'X' means you haven't watched the movie, and a digit between '0' and '9' represents your rating for it. Also you will be given a String friendsEvaluations, with each element representing movie ratings given by one of your friends. All elements of friendsEvaluations will be formatted the same as yourEvaluations. The last character of all elements of friendsEvaluations will represent "The CoderMan" - the movie you must rate (the last character of yourEvaluations will also represent "The CoderMan" and will always be 'X').
To rate "The CoderMan", you will need to calculate the deviation between you and each of your friends. It can be found as an average of absolute differences between you and your friend's ratings for all movies you both have watched (if there are no such movies, don't take the friend into account). For example, if you have rated 5 movies as "51X6X", and your friend's ratings are "2X97X", we count only the first and the fourth movies. This gives us the deviation equal to (|5 - 2| + |6 - 7|)/2 = (3 + 1)/2 = 2.
Throw away from your calculations all people whose deviation is greater than maximalDeviation and those who haven't rated "The CoderMan" yet. For all the people who are left, calculate and return the average of the ratings they've given to "The CoderMan". If none of your friends satisfies the criteria, return -1.