P

@praveen11

check whether if a char is present in string or not

C++
4 years ago
#include <iostream> #include<string> using namespace std; int main() { string s; cin>>s; if(s.find('a')!=string::npos){ cout<<"yes"; } else{

reverse substrings in paranthesis in c++

C++
4 years ago
#include <iostream> #include <stack> #include <algorithm> using namespace std; int main() { string s; cin>>s; stack<int> st; for(int i=0;i<s.length();i++){ if(s[i]=='('){

5x5 pattern "I/J"

Python
4 years ago
s=input() l=[] for i in range(25): if(i==8): l.append("I/J") elif(i<8): l.append(chr(i+65)) else: l.append(chr(i+66))

wipro question 2

Python
4 years ago
s=input() maxi=0 mini=256 for i in s: if(ord(i)>maxi): maxi=ord(i) if(ord(i)<mini): mini=ord(i) print(maxi+mini)

wipro coding question

C++
4 years ago
#include <iostream> #include<vector> using namespace std; int main() { int h,f,j; cin>>h>>f>>j; vector<int> v; while(v.size()<j){ v.push_back(h); h=h+f;

longest increasing sequence length

Python
4 years ago
def lenlis(l): n=len(l) dp=[1]*n for i in range(1,n): for j in range(0,i): if(l[i]>l[j]): dp[i]=max(dp[i],dp[j]+1) return max(dp) l=[10, 22, 9, 33, 21, 50, 41, 60]

Aggressive cows

Python
4 years ago
def cows_can_place(diff,a,cows,n): count=1 curr=0 for i in range(1,n): if(a[i]-a[curr]>=diff): count+=1 curr=i if(count==cows): return True return False

sum of factors of a number

Python
4 years ago
import math def factors(n): sum=0 for i in range(1,int(math.sqrt(n))): if(n%i==0): if(n//i==i): sum+=i else: sum+=i+n//i return sum

factors of number in O(sqrt(n))

Python
4 years ago
import math def factors(n): l=[] for i in range(1,int(math.sqrt(n))): if(n%i==0): if(n//i==i): l.append(i) else: l.append(i) l.append(n//i)

combinations of a list

Python
4 years ago
def n_length_combo(lst, n): if n == 0: return [[]] l =[] for i in range(0, len(lst)): m = lst[i] remLst = lst[i + 1:]

python QP 4

Python
4 years ago
n=int(input()) for i in range(1,n+1): for j in range(1,n+1): if((i+j)>n): print("%",end="") else: print("@",end="") print()

python QP 3

Python
4 years ago
n=int(input()) y=n//360 if(n%360==0): print(str(y)+",0,0") else: m=(n%360)//30 if((n%360)%30==0): print(str(y)+","+str(m)+",0") else: d=(n%360)%30 #or d=n-(y*360+30*m)

python QP 2

Python
4 years ago
s="Hello, \\nPython\\n students" print(s)

python QP 1

Python
4 years ago
f,i = map(int,input().split()) ans=((f*12)+i)*2.54 print(ans)

printing series

Python
4 years ago
""" print the series 0 1 3 6 10 15.......... """ import sys sys.setrecursionlimit(10**6) def handshake(n): if(n==1):

calculating Nck values using dp

Python
4 years ago
l=[[]] def nck(n,k): if(k==0 or n==k): l[n][k]=1 return l[n][k] if(l[n][k]): return l[n][k] l[n][k]=nck((n-1),(k-1))+nck((n-1),k) return l[n][k]

pascal"s triangle

Python
4 years ago
""" for given n value we have to print the following pascals triangle if n=5 then output should be 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 """

set matrix zeroes

Python
4 years ago
def setmatrix(l,r,c): row=[0]*r col=[0]*c # for i in range(r): # row[i]=0 # for i in range(c): # col[i]=0 for i in range(r): for j in range(c): if(l[i][j]==0):

fibnocci series using dynamic programming

Python
4 years ago
def fib(n): f=[0,1] for i in range(2,n+1): f.append(f[i-1]+f[i-2]) return f[n] print(fib(9))

house robber

Python
4 years ago
def rob(l): dp=[0]*len(l) if(len(l)==0): return 0 if(len(l)==1): return l[0] if(len(l)==2): return max(l[0],l[1]) dp[0]=l[0] dp[1]=max(l[0],l[1])