Find the Most Common Response
You are given a 2D string array responses where each responses[i] is an array of strings representing survey responses from the i^th day.
Return the most common response across all days after removing duplicate responses within each responses[i]. If there is a tie, return the lexicographically smallest response.
Example 1
Input
responses = [["good","ok","good","ok"],["ok","bad","good","ok","ok"],["good"],["bad"]]Output
"good"After removing duplicates within each list,
good appears 3 times, while ok and bad each appear 2 times, so good has the highest frequency.Example 2
Input
responses = [["good","ok","good"],["ok","bad"],["bad","notsure"],["great","good"]]Output
"bad"After removing duplicates within each list,
bad, good, and ok each occur 2 times, and bad is lexicographically smallest among them.Constraints
- 1 <= responses.length <= 1000
- 1 <= responses[i].length <= 1000
- 1 <= responses[i][j].length <= 10
- responses[i][j] consists of only lowercase English letters