This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
DSA/midterm_prep/183-2.py
Claudio Maggioni (maggicl) d724db3cca Dangling exercises for midterm
2019-04-23 13:35:05 +02:00

30 lines
678 B
Python

#!/usr/bin/env python3
import sys
import math
def better_algo_X(A, k):
l = -1 * math.inf
r = math.inf
for i in range(0, len(A)):
c = 0
for j in range(i, len(A)):
print("i =", i, "j =", j, "c =", c)
if A[i] == A[j]:
c = c + 1
if c >= k:
if r - l > j - i:
l = i
r = j
print("l =", l, "r = ", r)
break
return [l, r]
A = []
for line in sys.stdin:
line = line.strip()
if line == '' or line == '\n':
break
A.append(int(line))
print(better_algo_X(A[1:], A[0]))