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:
"a"
💡 Note:
Each response appears exactly once after deduplication: a=1, b=1, c=1. All tied with frequency 1, so return lexicographically smallest: 'a'.
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
Understanding the Visualization
1
Input
2D array of survey responses with duplicates within days
2
Deduplicate
Remove duplicates within each day using sets
3
Count
Count frequency of each response across all days
4
Output
Return most frequent response (lexicographically smallest on ties)
Key Takeaway
🎯 Key Insight: Always deduplicate within each day first, then count across all days to find the global winner
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code