Python 기본 사항쉬움

n명이 r자리를 차지할 수 있는 순열

n명이 r자리를 차지할 수 있는 순열' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

두 개의 음수가 아닌 정수 nr(여기서 n >= r)를 취하고 순열 수, 즉 n 항목 중 r 항목을 배열하는 방법의 수를 반환하는 함수 compute_nPr(n, r)을 작성하세요. 공식은 nPr = n입니다! / (n - r)!.

예를 들어 5명이 3개의 자리에 앉고 싶다면 방법의 수는 5P3 = 5! / 2! = 120 / 2 = 60.

제약
  • 0 <= r <= n <= 20

Example 1
Input
compute_nPr(5, 3)
Output
60
Explanation

5P3 = 5! / (5-3)! = 120 / 2 = 60.

Example 2
Input
compute_nPr(4, 2)
Output
12
Explanation

4P2 = 4! / 2! = 24 / 2 = 12.

Example 3
Input
compute_nPr(6, 6)
Output
720
Explanation

6P6 = 6! / 0! = 720 / 1 = 720.

Need a Hint?
세트나 힙과 같은 Numbers 관련 데이터 구조를 사용해 보세요.
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 리소스

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