P

@praveen11

infytq question 1 8th evng

Python
4 years ago
def checkams(x,l): amstrong=0 for i in x: amstrong+=int(i)**l if(amstrong==int(x)): return True else: return False s=input()

infytq question 2 8th evng

Python
4 years ago
def palindrome(s): if(s==s[::-1] and len(s)>1): return True else: return False n=int(input()) l=[] for i in range(n): l.append([j for j in input().split(",")])

infytq 7th evng 1

Python
4 years ago
l=[int(i) for i in input().split()] res=[] for i in l: count=1 while(i>1): if(i%2==0): i=i//2 count+=1 elif(i%2!=0): i=(i*3)+1

Nearest palindrome

Python
4 years ago
def palindrome(s): if(s==s[::-1]): return True else: return False n=int(input()) ans=0 while(True): if(palindrome(str(n))):

Identify palindrome

Python
4 years ago
def reverse(s): return s[::-1] n=int(input()) sum=0 while(True): r=reverse(str(n)) sum=n+int(r) if(str(sum)==reverse(str(sum))): break

infytq python coding questions -1 6th mrng

Python
4 years ago
def binary(x): a=bin(x) a=a[0]+a[2:] if(len(a)==8): return a else: return '0'+a s=input() r='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'

python infytq-1 6th mrng

Python
4 years ago
s=[] c=0 for i in range(0,2): for j in range(0,4): c+=1 if(i<j): continue c-=1 s.append(c) print(s)

spiral matrix I -> order

Python
4 years ago
l=[] n=int(input()) for i in range(n): l.append([int(i) for i in input().split()]) print(l) ans=[] top,bottom = 0,len(l) left,right = 0,len(l[0]) while(top < bottom and left < right): for i in range(left,right):

rotate the matrix i.e. 90 degrees rotation of matrix

Python
4 years ago
l=[] n=int(input()) for i in range(0,n): l.append([int(j) for j in input().split()]) for i in range(n): print(l[i]) print("Reverse") l[:]=l[::-1] for i in range(n): print(l[i])

excel sheet columns

Python
4 years ago
n=int(input()) x='' while(n>0): if(n%26==0): x+='Z' n=(n-1)//26 else: x+=chr(64+(n%26)) n//=26 print(x[::-1])

concatenate chars and sum of the numbers

Python
4 years ago
s=input() x='' d='' sum=0 for i in s: if(i>='0' and i<='9'): d+=i else: if(d!=''): sum+=int(d)

longest contiguous subarray of a that is in b but not in c

Python
4 years ago
""" You are given three arrays of integers a, b, and c. Your task is to find the longest contiguous subarray of a containing only elements that appear in b but do not appear in c. Given, a=[2, 1, 7, 1, 1, 5, 3, 5, 2, 1, 1, 1] b=[1, 3, 5] c=[2, 3]

digits that occur the most number of times in the array

Python
4 years ago
""" Given an array of integers a, your task is to calculate the digits that occur the most number of times in the array. Return the array of these digits in ascending order. For a = [25, 2, 3, 57, 38, 41], the output should be solution(a) = [2, 3, 5]. Here are the number of times each digit appears in the array:

password generator

Python
4 years ago
s=input().split(',') print(s) s=[i.split(':') for i in s] print(s) res='' for i in range(len(s)): if(str(len(s[i][0])) in s[i][1]): res+=s[i][0][-1] else: flag=0

special reverse

Python
4 years ago
s=input() d={} l=[] for i in range(len(s)): if(s[i].isalnum()==False): d[i]=s[i] else: l.append(s[i]) l=l[::-1] print(l)

list as deque

Python
4 years ago
from collections import deque l=[1,2,3,4,5] d=deque(l) print(l,d)

deque in python and functions

Python
4 years ago
from collections import deque d=deque() d.append(1) d.append(2) d.append(3) d.append(4) d.append(5) print(d) d.appendleft(19) print(d)

odd count of sum of sub array of list

Python
4 years ago
l=[1,7,3,9,8] a=[[]] for i in range(len(l)+1): for j in range(i): a.append(sum(l[j:i])) print(a) count=0 for i in range(1,len(a)): if(a[i]&1): count+=1

infytq question-1

Python
4 years ago
s=input() l=[""]*26 for i in s: if((i>='a' and i<='z')): l[ord(i)-97]+=i elif(i>='A' and i<='Z'): l[ord(i)-65]+=i l1=[i for i in l if(i!='')] print(l1) i=0

maximum consecutive 1's in array

Python
4 years ago
l=[int(i) for i in input().split()] temp=maxi=0 for i in l: if(i==0): temp=0 else: temp+=1 maxi=max(maxi,temp) print(maxi)