Problem Statement
A popular way to suggest things you might like is to check things that your friends like. You decide to automate the suggestion process so that you have to check only things liked by at least N of your friends.
You are given a String[] friendsLikes which describes things that your friends like. The j-th character of the i-th element of friendsLikes is 'L' if friend i likes thing j, and is 'D' otherwise. You are also given N, the minimum number of friends that have to like something for it to be suggested. Return the 0-based indices of things liked by at least N of your friends. The indices must be sorted in increasing order.
You are given a String[] friendsLikes which describes things that your friends like. The j-th character of the i-th element of friendsLikes is 'L' if friend i likes thing j, and is 'D' otherwise. You are also given N, the minimum number of friends that have to like something for it to be suggested. Return the 0-based indices of things liked by at least N of your friends. The indices must be sorted in increasing order.
Definition
- Class:
- LikesFinder
- Method:
- likesToSuggest
- Parameters:
- String[], int
- Returns:
- int[]
- Method signature:
- int[] likesToSuggest(String[] friendsLikes, int N)
- (be sure your method is public)
Notes
- Note that the things you return don't have to be liked by the same subset of your friends; likes for each thing are analyzed independently.
Constraints
- friendsLikes will contain between 1 and 50 elements, inclusive.
- Each element of friendsLikes will contain the same number of characters.
- Each element of friendsLikes will contain between 1 and 50 characters, inclusive.
- Each character in friendsLikes will be 'L' or 'D'.
- N will be between 1 and (number of elements in friendsLikes), inclusive.
Examples
{"LLLL", "DLDL", "DDDD"}2
Returns: {1, 3 }{"LDDD", "DLDD", "DDLD", "DDDL"}1
Returns: {0, 1, 2, 3 }Each thing is liked by one friend, and that's enough for it to get into the list.{"DDDLD", "DLDDD", "DDLDD"}2
Returns: { }All things are liked by at most one friend, so there's nothing to suggest.{"LDLDLD"}1
Returns: {0, 2, 4 }{"DDDDDDDDD","DDDDDDDDD","DDDDDDDDD","DDDDDDDDD"}1
Returns: { }Your friends don't really like anything.