Skip to content

[Cyjin-jani] WEEK 01 solutions#2369

Merged
Cyjin-jani merged 6 commits intoDaleStudy:mainfrom
Cyjin-jani:main
Mar 7, 2026
Merged

[Cyjin-jani] WEEK 01 solutions#2369
Cyjin-jani merged 6 commits intoDaleStudy:mainfrom
Cyjin-jani:main

Conversation

@Cyjin-jani
Copy link
Contributor

@Cyjin-jani Cyjin-jani commented Mar 3, 2026

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

tempArr[val].push(+key);
}

const answer = tempArr.flat();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 깔끔한 코드 잘 보았습니다!!

Suggested change
const answer = tempArr.flat();
const answer = [];
for (let i = tempArr.length - 1; i >= 0; i--) {
for (let num of tempArr[i]) {
answer.push(num);
if (answer.length === k) return answer;
}
}
return answer;

flat() 를 사용하는 방식도 좋지만 전체 버킷을 모두 펼치는 대신에 tempArr를 뒤에서부터 순회하면서 answer 에 필요한 k개만 담아 바로 리턴하는 방식도 고려해보시면 좋을 것 같아요.

공간복잡도는 동일한 O(n) 이지만 k가 작은 경우에는 새 배열을 추가로 생성하기보다는 k개의 개수만 모아서 반환하는 방식이 효율적일 수도 있을거 같네요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@doh6077
좋은 피드백 감사합니다!🙌

(변명 아닌 변명입니다만..?) flat을 적용했던 이유는 시간복잡도 제한 때문에 무의식적으로 이중 for문을 배제하고 해결하려고 했던 것 같습니다😅

제안해주신대로 변경해도 어차피 제한된 k 범위에서만 확인하고 전체를 순회하는게 아니니..
시간복잡도 O(n)이 변하지는 않는 것 같아서 굳이 flat을 사용할 필요가 없겠네요..!

7bdd0d1로 수정 사항 반영해보았습니다 ㅎㅎ
보다 더 좋은 최적화 방법을 알게 되어 너무 감사합니다 :)

@Cyjin-jani Cyjin-jani moved this from Solving to In Review in 리트코드 스터디 7기 Mar 6, 2026
@Cyjin-jani Cyjin-jani merged commit 9a129c6 into DaleStudy:main Mar 7, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 7기 Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

2 participants