상위 150개 인터뷰중간

코인 변경

'Coin Change' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

중간

다양한 액면가의 동전을 나타내는 정수 배열 동전과 총 금액을 나타내는 정수 금액이 제공됩니다.

해당 금액을 구성하는 데 필요한 최소 개수의 동전을 반환합니다. 해당 금액을 동전 조합으로 채울 수 없는 경우 -1을 반환합니다.

당신은 각 종류의 동전이 무한히 많다고 가정할 수 있습니다.

coinChange(coins: List[int], amount: int) -> int 함수를 작성하세요.

제약
  • 1 <= len(coins) <= 12
  • 1 <= coins[i] <= 2^31 - 1
  • 0 <= amount <= 10^4

Example 1
Input
coins = [1,2,5], amount = 11
Output
3
Explanation

11 = 5 + 5 + 1

Example 2
Input
coins = [2], amount = 3
Output
-1
Explanation

3 cannot be formed using only coins of denomination 2.

Example 3
Input
coins = [1], amount = 0
Output
0
Explanation

No coins are needed to make amount 0.

Need a Hint?
세트나 힙과 같은 1D DP 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.