Find the Most Common Response - Problem
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.
Input & Output
Example 1 — Basic Deduplication and Counting
$
Input:
responses = [["happy","sad","happy"],["sad","angry"]]
›
Output:
"sad"
💡 Note:
Day 1 unique responses: {happy, sad}. Day 2 unique responses: {sad, angry}. Total counts: happy=1, sad=2, angry=1. Most frequent is 'sad' with count 2.
Example 2 — Lexicographic Tie-Breaking
$
Input:
responses = [["a","b"],["b","c"]]
›
Output:
"b"
💡 Note:
Day 1 unique responses: {a, b}. Day 2 unique responses: {b, c}. Total counts: a=1, b=2, c=1. Most frequent is 'b' with count 2.
Example 3 — Multiple Days Same Response
$
Input:
responses = [["good"],["good","bad"],["good"]]
›
Output:
"good"
💡 Note:
After deduplication per day: Day 1: {good}, Day 2: {good, bad}, Day 3: {good}. Counts: good=3, bad=1. Most frequent is 'good'.
Constraints
- 1 ≤ responses.length ≤ 100
- 1 ≤ responses[i].length ≤ 100
- 1 ≤ responses[i][j].length ≤ 100
- responses[i][j] consists of lowercase English letters only
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code