im getting wrong answer in this problem:CodeChef: Practical coding for everyone
Help me with my code:
import math
cnt=int(input())
str1=input()
a=len(str1)
if cnt>0 and cnt<=math.pow(10,5) and a>0 and a<math.pow(10,8):
voi=0
list1=[]
for letter in str1:
if letter!=' ':
list1.append(letter)
#check
for n in range(1,cnt):
for x in range(0,n):
if list1[n]<list1[x]:
voi=voi+1
print(voi)
You do not need to explicitly check
if cnt>0 and cnt<=math.pow(10,5) and a>0 and a<math.pow(10,8):
voi=0
It is given that it is true.
Your input format is wrong
It should be
list1= list(map(int, input().split()))
This next part is too slow.
for n in range(1,cnt):
for x in range(0,n):
if list1[n]<list1[x]:
voi=voi+1
This is O(n^2) and will not pass the time limit.
1 Like
[quote=“everule1, post:2, topic:73542”]
for n in range(1,cnt):
for x in range(0,n):
if list1[n]<list1[x]:
voi=voi+1
Can u tell me how i can fix this problem, I can’t find any other way of doing the same thing