Ctrl K

The k-th Word With No Repeats

Easy
You are given a list of words words and a number k. Call a word a loner if it occurs in the list exactly once. Scan the list from left to right and return the k-th loner you meet (counting from one). If there are fewer than k loners, return the empty string "".
Example 1
words=["sun", "cat", "sky", "cat", "owl"], k=2 → 'sky'

The words seen exactly once are "sun", "sky" and "owl", in that order. The second one is "sky".

Example 2
words=["ab", "ab", "x"], k=2 → ''

The only word without a repeat is "x"; there is no second one, so the answer is an empty string.

Example 3
words=["q", "r", "s"], k=3 → 's'
Constraints
  • 1 ≤ k ≤ len(words) ≤ 1000
  • 1 ≤ len(words[i]) ≤ 20
  • words[i] consists of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWords From Letter Tiles EasyWords From Working Keys EasyWords Listed Once in Both EasyPairs With the Same Letter Set EasyMost Searched Words Medium
loading Python…
Input
words=["sun", "cat", "sky", "cat", "owl"], k=2
Expected
'sky'

Run checks the first 3 tests in your browser. Submit checks all 107 tests on the server, hidden ones included.