💡 시간복잡도와 공간복잡도를 시작전에 확인 후 설계를 짜자

<오답 코드>
from itertools import permutations
N = int(input())
for _ in range(N):
flag = 0
first, second = input().split(' ')
result = permutations(first, len(first))
for val in result:
if second == ''.join(val):
flag = 1
if flag == 0:
print("Impossible")
else:
print("Possible")
<정답 코드>
N = int(input())
for _ in range(N):
first, second = input().split(' ')
if sorted(first) == sorted(second):
print("Possible")
else:
print("Impossible")
💡 코딩스터디 중 기발한 접근 방법
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input().strip())
for _ in range(n):
str1, str2 = input().split()
# Counter 객체로 각 문자의 빈도수를 한 번에 계산
print("Possible" if Counter(str1) == Counter(str2) else "Impossible")