0% found this document useful (0 votes)
174 views15 pages

Wipro Coding

The document contains code snippets written in Python and C for solving problems related to strings, arrays, sorting, prime numbers, and other algorithmic challenges. Many of the code snippets take input, perform operations like sorting, filtering or calculations on the input and print the output. Overall the document appears to be a collection of coding problems and their solutions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
174 views15 pages

Wipro Coding

The document contains code snippets written in Python and C for solving problems related to strings, arrays, sorting, prime numbers, and other algorithmic challenges. Many of the code snippets take input, perform operations like sorting, filtering or calculations on the input and print the output. Overall the document appears to be a collection of coding problems and their solutions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

#company tag

S=input()
res=""
for i in range(0,len(S)-1,2):
if ord(S[i])>ord(S[i+1]):
res+=S[i]
else:
res+=S[i+1]
if len(S)%2!=0:
res+=S[-1]
print(res)

#credit score
N=int(input())
lst=list(map(int,input().split()))
lst.sort()
mi=lst[-1]*lst[-2]
for i in range(N-1):
for j in range(i+1,N):
k=lst[i]*lst[j]
if k<mi:
mi=k
a=lst[i]
b=lst[j]
print(b+a)

#online english learning website


str=input()
x=int(input())
l=[]
counts = {}
words = str.split()
for word in words:
if word in counts:
counts[word] += 1
else:
counts[word] = 1
for k,v in counts.items():
if counts[k]>=x:
l.append(k)
l.sort()
print(" ".join(l))
#mobile company
n=int(input())
r=0;
k=n
while(n>0):
x=n%10
r=r*10+x
n=n//10
print(k-r)

#perfect match
n=int(input())
k=int(input())
arr=list(map(int,input().split()))
res=[]
for i in arr:
r=i%k
res.append(r)
print(sum(res))

#cat lex
str=input()
x=int(input())
l=[]
counts = {}
words = str.split()
for word in words:
if word in counts:
counts[word] += 1
else:
counts[word] = 1
for k,v in counts.items():
if counts[k]>=x:
l.append(k)
l.sort()
print(" ".join(l))
#Company product code
n=int(input())
arr=list(map(int,input().split()))
counts = {}
for i in arr:
if i in counts:
counts[i] += 1
else:
counts[i] = 1
max1=min1=s=t=0
for k,v in counts.items():
if counts[k]>=max1:
max1=counts[k]
t=k
if counts[k]<=min1:
min1=counts[k]
s=k
print(t-s)

#climate code
n,l,r=map(int,input().split())
arr=list(map(int,input().split()))
for i in arr:
if (i>l) or (i<r):
print(i,end=" ")
#prime and n prime
n=int(input())
flag=0
p=[]
np=[]
arr=list(map(int,input().split()))
for i in arr:
for k in range(2, i):
if (i % k) == 0:
flag = 1
break
if flag==1:
np.append(i)
else:
p.append(i)
flag=0
for i in p:
print(i,end=" ")
for i in np:
print(i,end=" ")

#decimal to binary
n=int(input())
y=1
bin=0
while(n>0):
x=n%2
bin=bin+x*y
n=n//2
y=y*10
print(bin)

#apparal code
n=int(input())
if (n >= 2) and (n<=1000000):
arr=list(map(int,input().split()))
arr.sort()
print(arr[-1]+arr[-2])

s=input()
max=min=ord(s[0])
for i in range(0,len(s)):
if ord(s[i])> max:
max=ord(s[i])
if ord(s[i])< min:
min=ord(s[i])
print(min,max)

m=input()
l=len(m)
a=[]
for k in m:
a.append(int(k))
n=int(m)
print(a)
if n>0 and n<= 100000:
if n%2==0:
for i in range(0,l-1,2):
temp=a[i]
a[i]=a[i+1]
a[i+1]=temp

else:
for i in range(0,l-2,2):
temp=a[i]
a[i]=a[i+1]
a[i+1]=temp
i=i+1
for i in a:
print(i,end="")

#Gamming hub
n=int(input())
l=list(map(int,input().split()))
k,j=map(int,input().split())
c=0
for a in l:
if ((k%a==0) and (j%a==0)):
c=c+1
if n>0 and n<=1000:
if k>=0 and k<=1000 and j>=0 and j<=1000:
print(c)

#max product min product difference


n=int(input())
a=list(map(int,input().split()))
min=max=a[0]*a[1]
for i in range(0,n):
for j in range(i+1,n):
if a[i]*a[j] > max:
max=a[i]*a[j]
if a[i]*a[j] < min:
min=a[i]*a[j]
print(max-min)

#Rating problem
#include <stdio.h>
int main()
{
int p;
scanf("%d",&p);
if ((p>=30) && (p<=50))
printf("Average");
if ((p>=51) && (p<=60))
printf("Good");
if ((p>=61) && (p<=80))
printf("Excellent");
if ((p>=81) && (p<=100))
printf("Outstanding");
return 0;
}

#online match course


k,l,m=map(int,input().split())
a=list(map(int,input().split()))
s=b=0
for i in range(l-1,m):
s=a[i]+s
print(s)
#perfect qube problem
n=int(input())
if n>0 and n<=1000000:
c=0
a=list(map(int,input().split()))
for k in a:
if(round(k**(1/3))**3==k):
c=c+1
print(c)

online test
n=int(input())
s=0
m=0
a=0
while(n>0):
x=n%10
s=s+x
n=n//10
if s<=26:
s=s+ord("A")
print(chr(s)-1)
else:
print(s)
while(s>0):
a=s%10
m=m+a
s=s//10
print(chr(m+ord("A")-1))

cosmotic
n=int(input())
l="abcdefghij"
s=""
if n>=0 and n<=1000000:
while(n>0):
x=n%10
s=s+l[x]
n=n//10
print(s[::-1])

s=input()
c=0
for i in s:
if i.isnumeric():
c=c+1
print(c)

discount perfect cube..

n=int(input())
l=list(map(int,input().split()))
s=sum(l)
m=0
if(round(s**(1/3))**3==s):
print("Yes")
else:
for i in range(0,100000):

if(s>(i**3)):
continue
else:
m=i
break
print((m**3)-s)

#teacher even odd


n=int(input())
l=list(map(int,input().split()))
even=[]
odd=[]
if n >=0 and n<=1000:
for k in l:
print(k)
if k%2==0:
even.append(k)
print("e")
else:
odd.append(k)
print("o")
for i in even:
print(i,end="")
for i in odd:
print(i,end="")

#lucky loterry
n=int(input())
l=list(map(int,input().split()))
max1=0
for i in l:
if max1 <l.count(i):
max1=i
maxn=i
print(maxn)

#digit even add 1 odd sub -1


n=int(input())
m=str(n)
l=[]
if n>0 and n<=1000000000:
for k in m:
x=int(k)
if x%2==0:
x=x+1
else:
x=x-1
print(x,end="")
#swaping cosigutive digits encrypted code
n=int(input())
if n>=0 and n<=1000000:
m=str(n)
x=""
for i in range(0,len(m)-1,2):
x=x+m[i+1]
x=x+m[i]

if(len(m)%2!=0):
x=x+m[-1]
print(x)

#list partition reverse

n=int(input())
l1=[]
l2=[]
l3=[]
l=list(map(int,input().split()))
a,b=map(int,input().split())
print(l,a,b)
l1=l[0:a]
l2=l[a:b+1]
if b<n:
l3=l[b+1:len(l)]
l4=l1+l2[::-1]+l3
print(l4)
for i in l4:
print(i,end=" ")
lis=[int(digit) for digit in str(number)]

n=int(input())
a,b,c=list(map(int,input().split()))
maxa1=0
maxa2=0
while(a>0):
x=a%10
if maxa1<x:
maxa2=maxa1
maxa1=x
a=a//10
while(b>0):
x=b%10
if maxb1<x:
maxb2=maxb1
maxb1=x
b=b//10
while(c>0):
x=c%10
if maxc1<x:
maxc2=maxc1
maxc1=x
c=c//10

n=int(input())
k=int(input())
l=list(map(int,input().split()))
s=0
for i in l:
if i>= 0 and i<=1000000:
x=i%k
s=s+x
print(s)

n=int(input())
min1=0
while(a>0):
x=a%10
if min1>x:
min1=x
a=a//10
print(min1)

#encryption
k=int(input())
s=input()
for i in s:
print(chr(ord(i)+k),end="")

n=int(input())
ev=0
if n>0 and n<=1000000000:
while(n>0):
x=n%10
if x%2==0:
ev=ev+1

n=n//10
print(ev)

n=input()
max1=0
min1=100000

for i in n:
if ord(i) > max1:
max1=ord(i)
if ord(i)<min1:
min1=ord(i)
print(max1+min1)
#bucket id
n=int(input())
l=[]
while n>0:
x=n%10
l.append(x)
n=n//10
ks=""
km=""
k=sorted(l,reverse=True)
for i in k:
ks=ks+str(i)
m=sorted(l,reverse=False)
for i in m:
km=km+str(i)
print(int(ks)+int(km))

#container
n=int(input())
l=list(map(int,input().split()))
k=sorted(l)
j=len(k)-1
print(k)
m=0
for i in range(0,len(k),2):
print(k[j],k[m])
print()
j=j-1
m=m+1

#players
n=int(input())
l=list(map(int,input().split()))
a,b=map(int,input().split())
c=0
for k in l:
if a%k==0 and b%k==0:
c=c+1
if n>0 and n<=1000:
print(c)
fibonacci
nterms = int(input())
n1, n2 = 0, 1
count = 0
s=0
if nterms >= 0 and nterms<=100000:
if nterms == 1:
print(n1)
else:
while count < nterms:
s=s+n1
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
print(s)

#reverse differnce
n=int(input())
k=n
rev=0
while n>0:
x=n%10
rev=rev*10+x
n=n//10
print(n-rev)

#aAklip
N=input()
lst=[]
for i in N:
lst.append(ord(i))
print(max(lst)+min(lst))

#Apparal code
n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
print(arr[-k])
#today apparal
n=int(input())
arr=list(map(int,input().split()))
c=0
for i in arr:
if i>=0:
c=c+1
print(c)

#prime numbers
#include <stdio.h>

int main()
{
int i, Number, count,k;

scanf("%d",&k);
for(Number = 1; Number <= k; Number++)
{
count = 0;
for (i = 2; i <= Number/2; i++)
{
if(Number%i == 0)
{
count++;
break;
}
}
if(count == 0 && Number != 1 )
{
printf(" %d ", Number);
}
}
return 0;
}

You might also like