I have been trying to solve this MSV (problem name) challenge from October Long challenge 2019.
The solution with which I came was accepted for 3 out of 5 sub tasks and rejected for two subtasks with TLE error. After the end of challenge, when I saw the answer of this problem, I found after checking that my solution is taking less time than this one in every possible case we can test for.
Please what is wrong with my code, and help me with your explanation. Below is my code because I am not able to upload .py file here.
t = int(input())
for _ in range(t):
n = int(input())
lists = list(map(int, input().rstrip().split()))
lcount = 0
rcount = 0
max_count = 0
m = 0
i = 1 j = n-1 while i <= j: for k in range((n-1)-m): if lists[k]%lists[j] == 0: rcount += 1 if k < i and lists[k]%lists[i] == 0: lcount += 1 count = max(lcount, rcount) if count > max_count: max_count = count if count != 0 and count > i: i = count lcount = 0 rcount = 0 j -= 1 i+=1 m += 1 print(max_count)