Skip to content

[PGS] 옹알이(2) - #59

Open
been12151 wants to merge 11 commits into
mainfrom
week2/babbling
Open

[PGS] 옹알이(2)#59
been12151 wants to merge 11 commits into
mainfrom
week2/babbling

Conversation

@been12151

Copy link
Copy Markdown
Owner

🍪 문제 이름

Resolve: 옹알이 (2)

🍊 문제 정의

input

  • babbling : 머쓱이 조카가 옹알이한 단어들이 담긴 문자열 배열 (1 ≤ 길이 ≤ 100, 각 단어 길이 1 이상 30 이하, 알파벳 소문자로만 구성)

output

  • babbling 중 "aya", "ye", "woo", "ma"의 조합으로만 이루어지고, 같은 발음이 연속되지 않는 단어의 개수

예시

babbling result
["aya", "yee", "u", "maa"] 1
["ayaye", "uuuma", "yeye", "yemawoo", "ayaayaa"] 2

🍑 알고리즘 설계

각 단어에 대해 4가지 발음(words)을 순서대로 찾아 발음 + " "로 치환함. 치환 후 split()으로 분리하면 발음 단위의 리스트(parts)가 만들어짐.
parts의 모든 원소가 words에 속하는지 확인하고, groupby(parts)로 연속된 같은 발음이 없는지 동시에 체크해서 둘 다 통과하면 카운트 증가.

from itertools import groupby

def solution(babbling):
    words = ["aya", "ye", "woo", "ma"]
    answer = 0

    for word in babbling:
        for wd in words:
            word = word.replace(wd, wd + " ")
        parts = word.split()
        if all(p in words for p in parts) and len(parts) == len(list(groupby(parts))):
            answer += 1

    return answer

🥝 최악 수행 시간 복잡도

  • O(n × m) (n = babbling의 길이, m = 각 단어의 길이)
  • 각 단어마다 4가지 발음에 대해 replace()를 수행하고(상수), 이후 split(), all(), groupby() 모두 단어 길이에 비례하므로 전체 O(n × m)

🍰 특이 사항 (Optional)

연속된 같은 발음 체크를 groupby()로 처리

@been12151
been12151 requested review from gayo73 and yangyeeeun July 8, 2026 00:09
@been12151 been12151 self-assigned this Jul 8, 2026
@been12151 been12151 linked an issue Jul 9, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PGS] 옹알이 (2) / level1

2 participants