Type Here to Get Search Results !

codemind python lists,tuples,dict

 Third maximum number


a=int(input())
b=set(map(int,input().split()))
c=list(b)
c.sort()
if(len(c)>2):
    print(c[-3])
else:
    print(max(b))



monk and welcome problem


a=int(input())
b=list(map(int,input().split()))
c=list(map(int,input().split()))
for i in range(a):
    print(b[i]+c[i],end=' ')



find the duplicate number


from collections import Counter 
a=int(input())
l=list(map(int,input().split()))
d=dict(Counter(l))
for i in d:
    if d.get(i)!=1:
        print(i)



find first and last position


a=int(input())
b=''.join(input().split())
t=input()
n1=b.find(t)
n2=b.rfind(t)
print(n1,n2)



max consecutive ones

l=int(input())
a=''.join(input().split())
max=0
for i in range(1,l+1):
    if a.find('1'*i)!=-1:
        max=i
print(max)



majority element

import statistics
a=int(input())
b=[int(i) for i in input().split()]
print(statistics.mode(b))


squares of sorted array

a=int(input())
l=list(map(int,input().split()))
l2=[]
for i in l:
    l2.append(i*i)
l2.sort()
for i in l2:
    print(i,end=' ')


Find numbers with even number of digits

a=input()
l=list(map(str,input().split()))
count=0
for i in l:
    if len(i)%2==0:
        count+=1
print(count)<



how many numbers are smaller than

def count(i,l):
    count=0
    for j in l:
        if j<i:
            count+=1
    return count
n=int(input())
l=list(map(int,input().split()))
for i in l:
    print(count(i,l),end=' ')



sum of odd and even digits

a=int(input())
b=list(map(int,input().split()))

sum,index=0,0
for i in b:
    if index%2==0:
        sum-=i
    else:
        sum+=i
    index+=1
if(sum==0):
    print('YES')
else:
    print('NO')


unique maximum number

from collections import Counter 
a=int(input())
l=list(map(int,input().split()))
d=dict(Counter(l))
l2=[]
for i in d:
    if d.get(i)==1:
        l2.append(i)
if l2:
    print(max(l2))
else:
    print(-1)


display unique values

a=int(input())
b=list(map(int,input().split()))
c=set(b)
count=0
for i in c:
    if i  not in b[b.index(i)+1:]:
        print(i,end=' ')
        count+=1
if(count==0):
    print(-1)



clothing store


from collections import Counter
n=int(input())
l1=map(int,input().split())
l2=dict(Counter(l1))
l3=l2.values()
sum=0
for i in l3:
    sum+=i//2
print(sum)






Tags