문제 · 문자열 보통 Python ·
Most frequent words
A word is a maximal run of ASCII letters (a–z, A–Z); everything else separates words. Words are compared case-insensitively and returned in lowercase. Return the k most frequent words, ordered by count (highest first) and then alphabetically. If there are fewer than k distinct words, return all of them.
함수 시그니처
def top_words(text: str, k: int) -> list[str]:예제
top_words('the cat and the hat. The end!', 2) # -> ['the', 'and']
top_words('', 3) # -> []
top_words("Don't stop", 5) # -> ['don', 'stop', 't']제한 시간이 적용되는 6 개의 비공개 테스트와 1 개의 대규모 입력 테스트가 추가로 진행되며, 입력값은 공개되지 않습니다. 문제는 모델에 영어로 주어집니다.
1위Google Gemini 3.8 Flash해결 · 테스트 10/10 통과응답 소요 1.7 초 · 실행 시간 194 ms · $0.0006 ✓ top_words('the cat and the hat. The end!', 2)기댓값 ['the', 'and'] <1 ms ✓ top_words('', 3)기댓값 [] <1 ms ✓ top_words("Don't stop", 5)기댓값 ['don', 'stop', 't'] <1 ms ✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms⏱ 188 ms코드
import re from collections import Counter def top_words(text: str, k: int) -> list[str]: if k <= 0: return [] words = re.findall(r"[a-zA-Z]+", text.lower()) counts = Counter(words) # Sort by (-count, word) and take the top k return sorted(counts.keys(), key=lambda w: (-counts[w], w))[:k]1위OpenAI GPT-6 Luna해결 · 테스트 10/10 통과응답 소요 1.5 초 · 실행 시간 203 ms · $0.0001 ✓ top_words('the cat and the hat. The end!', 2)기댓값 ['the', 'and'] 1 ms ✓ top_words('', 3)기댓값 [] <1 ms ✓ top_words("Don't stop", 5)기댓값 ['don', 'stop', 't'] <1 ms ✓ <1 ms✓ <1 ms✓ <1 ms✓ 1 ms✓ <1 ms✓ 7 ms⏱ 190 ms코드
import re from collections import Counter def top_words(text: str, k: int) -> list[str]: if k <= 0: return [] counts = Counter(re.findall(r"[A-Za-z]+", text.lower())) return sorted(counts, key=lambda word: (-counts[word], word))[:k]1위Z.ai GLM 5.3해결 · 테스트 10/10 통과응답 소요 683 ms · 실행 시간 203 ms · $0.0002 ✓ top_words('the cat and the hat. The end!', 2)기댓값 ['the', 'and'] <1 ms ✓ top_words('', 3)기댓값 [] <1 ms ✓ top_words("Don't stop", 5)기댓값 ['don', 'stop', 't'] 1 ms ✓ 1 ms✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms⏱ 196 ms코드
import re from collections import Counter def top_words(text: str, k: int) -> list[str]: if k <= 0: return [] words = re.findall(r'[A-Za-z]+', text.lower()) c = Counter(words) return [w for w, _ in sorted(c.items(), key=lambda x: (-x[1], x[0]))[:k]]1위Anthropic Claude Haiku 5.5해결 · 테스트 10/10 통과응답 소요 1.0 초 · 실행 시간 247 ms · $0.0001 ✓ top_words('the cat and the hat. The end!', 2)기댓값 ['the', 'and'] <1 ms ✓ top_words('', 3)기댓값 [] 1 ms ✓ top_words("Don't stop", 5)기댓값 ['don', 'stop', 't'] <1 ms ✓ 4 ms✓ <1 ms✓ 2 ms✓ <1 ms✓ 3 ms✓ <1 ms⏱ 234 ms코드
import re from collections import Counter def top_words(text: str, k: int) -> list[str]: if k <= 0: return [] words = re.findall(r'[A-Za-z]+', text) counts = Counter(w.lower() for w in words) items = sorted(counts.items(), key=lambda kv: (-kv[1], kv[0])) return [w for w, _ in items[:k]]
토큰 비용: $0.0010 · 진행 방식 및 점수 산정 안내 →