Python 기본 사항하드

최대 악수 횟수

'최대 핸드셰이크 수' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

하드

방에 있는 사람의 수를 나타내는 양의 정수 n을 취하고 모든 사람이 다른 사람과 정확히 한 번씩 악수할 경우 발생할 수 있는 최대 악수 횟수를 반환하는 함수 max_handshakes(n)을 작성하세요.

공식은 max_handshakes = n * (n - 1) / 2입니다. 이는 각 쌍의 사람들이 한 번씩 악수를 하기 때문입니다.

제약
  • 1 <= n <= 10^4

Example 1
Input
max_handshakes(5)
Output
10
Explanation

5 people: 5 × 4 / 2 = 10 handshakes. Each of the 5 people shakes hands with 4 others, divided by 2 since each handshake is counted twice.

Example 2
Input
max_handshakes(2)
Output
1
Explanation

2 people can only have 1 handshake between them.

Example 3
Input
max_handshakes(10)
Output
45
Explanation

10 × 9 / 2 = 45 handshakes.

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 리소스

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