Python 기본 사항쉬움

배열에서 모든 대칭 쌍 찾기

'배열에서 모든 대칭 쌍 찾기' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

쌍 목록(2개 요소 목록)을 취하고 모든 대칭 쌍을 반환하는 함수 symmetric_pairs(arr)을 작성하세요. 쌍 [a, b]는 배열에 둘 다 존재하는 경우 다른 쌍 [b, a]와 대칭입니다. 쌍의 첫 번째 요소가 더 작은 정렬된 쌍 목록으로 결과를 반환합니다. 각 대칭 쌍은 한 번만 나타나야 합니다.

제약
  • 1 <= len(arr) <= 10^4
  • Each element is a list of 2 integers
  • -10^6 <= arr[i][j] <= 10^6

Example 1
Input
arr = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6]]
Output
[[1, 2], [3, 4]]
Explanation

[1,2] and [2,1] are symmetric. [3,4] and [4,3] are symmetric. [5,6] has no symmetric pair.

Example 2
Input
arr = [[1, 2], [3, 4]]
Output
[]
Explanation

No pair has its reverse in the array.

Example 3
Input
arr = [[10, 20], [20, 10]]
Output
[[10, 20]]
Explanation

[10,20] and [20,10] form a symmetric pair.

Need a Hint?
세트나 힙과 같은 배열별 데이터 구조를 사용하는 것을 고려해 보세요.
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 리소스

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