Advertisement
Egor_1425

Untitled

Apr 29th, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def solve():
  2.     a = list(map(int, input()))
  3.     left = 0
  4.     count = [0] * 3
  5.     count[a[0]-1] = 1
  6.     min_len = 2 * 10**5 + 1
  7.     for right in range(1, len(a)):
  8.         count[a[right]-1] += 1
  9.         while left <= right and count[a[left]-1] >= 2:
  10.             count[a[left]-1] -= 1
  11.             left += 1
  12.         if count[0] > 0 and count[1] > 0 and count[2] > 0 and right - left + 1 < min_len:
  13.             min_len = right - left + 1
  14.  
  15.     if min_len < 2 * 10**5 + 1:
  16.         return min_len
  17.     else:
  18.         return 0
  19.  
  20. for _ in range(int(input())):
  21.     print(solve())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement