String Pair
Problem Description
Now, once digit D is known find out all unordered pairs of numbers in input whose sum is equal to D. Refer example section for better understanding.
Input
Output
Time Limit
Examples
String Pair Solution
table = {0: ‘zero’, 1: ‘one’, 2: ‘two’, 3: ‘three’, 4: ‘four’, 5: ‘five’, 6: ‘six’, 7: ‘seven’, 8: ‘eight’, 9: ‘nine’, 10: ‘ten’, 11: ‘eleven’, 12: ‘twelve’, 13: ‘thirteen’, 14: ‘fourteen’, 15: ‘fifteen’, 16: ‘sixteen’, 17: ‘seventeen’, 18: ‘eighteen’, 19: ‘nineteen’, 20: ‘twenty’, 21: ‘twentyone’, 22: ‘twentytwo’, 23: ‘twentythree’, 24: ‘twentyfour’, 25: ‘twentyfive’, 26: ‘twentysix’, 27: ‘twentyseven’, 28: ‘twentyeight’, 29: ‘twentynine’, 30: ‘thirty’, 31: ‘thirtyone’, 32: ‘thirtytwo’, 33: ‘thirtythree’, 34: ‘thirtyfour’, 35: ‘thirtyfive’, 36: ‘thirtysix’, 37: ‘thirtyseven’, 38: ‘thirtyeight’, 39: ‘thirtynine’, 40: ‘forty’, 41: ‘fortyone’, 42: ‘fortytwo’, 43: ‘fortythree’, 44: ‘fortyfour’, 45: ‘fortyfive’, 46: ‘fortysix’, 47: ‘fortyseven’, 48: ‘fortyeight’, 49: ‘fortynine’, 50: ‘fifty’, 51: ‘fiftyone’, 52: ‘fiftytwo’, 53: ‘fiftythree’, 54: ‘fiftyfour’, 55: ‘fiftyfive’, 56: ‘fiftysix’, 57: ‘fiftyseven’, 58: ‘fiftyeight’, 59: ‘fiftynine’, 60: ‘sixty’, 61: ‘sixtyone’, 62: ‘sixtytwo’, 63: ‘sixtythree’, 64: ‘sixtyfour’, 65: ‘sixtyfive’, 66: ‘sixtysix’, 67: ‘sixtyseven’, 68: ‘sixtyeight’, 69: ‘sixtynine’, 70: ‘seventy’, 71: ‘seventyone’, 72: ‘seventytwo’, 73: ‘seventythree’, 74: ‘seventyfour’, 75: ‘seventyfive’, 76: ‘seventysix’, 77: ‘seventyseven’, 78: ‘seventyeight’, 79: ‘seventynine’, 80: ‘eighty’, 81: ‘eightyone’, 82: ‘eightytwo’, 83: ‘eightythree’, 84: ‘eightyfour’, 85: ‘eightyfive’, 86: ‘eightysix’, 87: ‘eightyseven’, 88: ‘eightyeight’, 89: ‘eightynine’, 90: ‘ninety’, 91: ‘ninetyone’, 92: ‘ninetytwo’, 93: ‘ninetythree’, 94: ‘ninetyfour’, 95: ‘ninetyfive’, 96: ‘ninetysix’, 97: ‘ninetyseven’, 98: ‘ninetyeight’, 99: ‘ninetynine’, 100: ‘hundred’}
vowels = {‘a’, ‘e’, ‘i’, ‘o’, ‘u’}
n = int(input())
ls = list(map(int, input().split()))
d = 0
def wordify(x) > int:
if x < 0 or x > 100:
return
su = 0
for c in table[x]:
if c in vowels:
su += 1
return su
def pair_sum(d, ls):
res = []
while ls:
num = ls.pop()
diff = d – num
if diff in ls:
res.append([diff, num])
res.reverse()
return res
for i in ls:
d += wordify(i)
# print(d)
print(table[len(pair_sum(d, ls))])
Elections
Problem Description
Constraints
Input
Output
Time Limit
Examples
A has 1 vote, B has 1 vote hence, output will be “Coalition government“.
Election Solutions
Moving Average
Problem Description
Constraints
Input
Output
Time Limit
Examples
Jogging Ground
Problem Description
Constraints
Input

 R denotes the radius of all four circles
 D1 denotes the distance centre of the second circle from left to the centre of the leftmost circle

 D2 denotes the distance centre of the third circle from left to the centre of the leftmost circle

 D3 denotes the distance centre of the last circle from left to the centre of the leftmost circle
Output
Time Limit
Examples
Zoo Design
Problem Description


Zoo needs to have minimum of X herbivores, Y carnivores and Z aquatic animals

Different types of animals will need different minimum area to thrive in

For animals of a given type, the minimum area required is the same

There is also a maximum limit for the overall area allocated for each animal type

Cost of fencing etc. is included in cost of enclosure

Exclude the essentials like pathways for tourists, from area and cost calculations

Constraints
Input
Output
Time Limit
Examples
·Thus the minimum cost of constructing the zoo adhering to all constraints is (250 * 100 + 150 * 1000 + 100 * 1500) = 325000
Max Sum Solution
print(count)
Even Odd Solution
Factor Of 3 Solution
Fill The Cube Solutions
import math n=int(input()) l=[] c=0 for i in range(n): l.append(list(map(str,input().split()))) for j in range(n): for k in range(n): if l[j][k]==’D’: c+=1 print(math.floor(math.sqrt(c)))
Factor Tree Solutions
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) a=[] for i in range(n): a.append(l[i]%3) z=a.count(0) o=a.count(1) t=a.count(2) if z==0 and o!=0 and t!=0: print(‘NO’) elif z==0 and t==0 and o!=0: print(‘YES’) elif z==0 and o==0 and t!=0: print(‘YES’) elif z<=(t+o): print(‘YES’) else: print(‘NO’)
Palindrome
def is_pallindrome(s): n = len(s) if n==1: return True for i in range(n//2): if s[i] != s[i1]: return False return True s = input() def f(s): for a in range(1,len(s)2): if is_pallindrome(s[:a]): for b in range(a+1,len(s)): if is_pallindrome(s[a:b]) and is_pallindrome(s[b:]): print(s[:a]) print(s[a:b]) print(s[b:]) return print(“not possible”)
Highway Lane Solution
TCS Wings 1 Java Coding Question
#includeusing namespace std; int main() { int n; cin >> n; int speed[n]; for(int i=0;i> speed[i]; if (n == 0) { printf(“%0.6f”,float(n)); return 0; } if(n == 1) { printf(“%0.6f”,float(n)); return 0; } double per = 1,group = 0; for(int i=1; i<=n; i++) { per *= i; for(int j=1,mult =1 ;j<=i; mult *= ++j ) { group += (per/mult); } } if (n%2 == 0) group–; group =n; printf(“%0.6f”,group/per); return 0; }
Corona Virus Solutions
#include#include#includeusing namespace std; int main() { string fever,cough,fatigue,sneezing,aches,nose,throat,diarea,headache,breath; //declaring the variables cout << “nCheck for whether you have coronavirus,cold or flu or none of them.: “; //asking the user to input the symptoms cout << “nDo you have fever:(common/rare/no): “; cin >> fever; cout << “Do you have fatigue:(common/sometimes/NO): “; cin >> fatigue; cout << “Do you have cough:(common/mild/NO): “; cin >> cough; cout << “Do you have sneezing:(common/NO): “; cin >> sneezing; cout << “Do you have aches:(common/sometimes/NO): “; cin >> aches; cout << “Do you have Runny or stuffy nose:(common/rare/sometimes/NO): “; cin >> nose; cout << “Do you have Sore throat:(common/sometimes/NO): “; cin >> throat; cout << “Do you have diarrhea:(rare/sometimes/NO): “; cin >> diarea; cout << “Do you have headaches:(common/rare/sometimes/NO): “; cin >> headache; cout << “Do you have Shortness of breath:(sometimes/NO): “; cin >> breath; if(fever== “COMMON” && fatigue==”SOMETIMES” && cough== “COMMON” && sneezing == “NO” && aches== “SOMETIMES” && nose==”RARE” && throat==”SOMETIMES” && diarea==”RARE” && headache==”SOMETIMES” && breath==”SOMETIMES”) { cout << “You have coronavirus!!!”; } else if(fever== “RARE” && fatigue==”SOMETIMES” && cough== “MILD” && sneezing == “COMMON” && aches== “COMMON” && nose==”COMMON” && throat==”COMMON” && diarea==”NO” && headache==”RARE” && breath==”NO”) { cout << “You have cold”; } else if(fever== “COMMON” && fatigue==”COMMON” && cough== “COMMON” && sneezing == “NO” && aches== “COMMON” && nose==”SOMETIMES” && throat==”SOMETIMES” && diarea==”SOMETIMES” && headache==”COMMON” && breath==”NO”) { cout << “You have Flu”; } else{ cout << “You dont have any of 3 viruses”; } }
Particle
#include<bits/stdc++.h>
#include<math.h>
#include<cmath>
using namespace std;
float dist(float x1,float x2,float y1,float y2,float z1,float z2){
float d=0;
d=sqrt(pow(x2 – x1, 2) + pow(y2 – y1, 2) + pow(z2 – z1, 2) * 1.0);
return d;
}
float area(float side1, float side2, float side3 ){
float s = (side1+side2+side3)/2;
float are = sqrt(s*(sside1)*(sside2)*(sside3));
return are;
}
int main(){
float h,a,b,c,d,va,vb,vc,vd;
cin>>h>>a>>b>>c>>d>>va>>vb>>vc>>vd;
char da,db,dc,dd;
cin>>da>>db>>dc>>dd;
if(da==’D’){
va=va*(1);
}
if(db==’D’){
vb=vb*(1);
}
if(dc==’D’){
vc=vc*(1);
}
if(dd==’D’){
vd=vd*(1);
}
float xa=0,ya=h*(1);
float xb=h,yb=h*(1);
float xc=h,yc=0;
float xd=0,yd=0;
float z[100][4];
for( int i=0;i<100;i++){
for( int j=0;j<4;j++){
z[i][j]=0;
}
}
z[0][0]=a;
z[0][1]=b;
z[0][2]=c;
z[0][3]=d;
for( int i=1;i<100;i++){
z[i][0]=z[i1][0]+va;
z[i][1]=z[i1][1]+vb;
z[i][2]=z[i1][2]+vc;
z[i][3]=z[i1][3]+vd;
if(z[i][0] > h){
z[i][0]=h;
}
if(z[i][0] < 0){
z[i][0]=0;
}
if(z[i][1] > h){
z[i][1]=h;
}
if(z[i][1] < 0){
z[i][1]=0;
}
if(z[i][2] > h){
z[i][2]=h;
}
if(z[i][2] < 0){
z[i][2]=0;
}
if(z[i][3] > h){
z[i][3]=h;
}
if(z[i][3] < 0){
z[i][3]=0;
}
}
float ab[100];
for( int i=0;i<100;i++){
ab[i]=dist(xa,xb,ya,yb,z[i][0],z[i][1]);
}
float bc[100];
for( int i=0;i<100;i++){
bc[i]=dist(xb,xc,yb,yc,z[i][1],z[i][2]);
}
float ac[100];
for( int i=0;i<100;i++){
ac[i]=dist(xa,xc,ya,yc,z[i][0],z[i][2]);
}
float ad[100];
for( int i=0;i<100;i++){
ad[i]=dist(xa,xd,ya,yd,z[i][0],z[i][3]);
}
float bd[100];
for( int i=0;i<100;i++){
bd[i]=dist(xb,xd,yb,yd,z[i][1],z[i][3]);
}
float cd[100];
for( int i=0;i<100;i++){
cd[i]=dist(xc,xd,yc,yd,z[i][2],z[i][3]);
}
float abc[100];
for(int i=0;i<100;i++){
abc[i]=area(ab[i],bc[i],ac[i]);
}
float adc[100];
for(int i=0;i<100;i++){
adc[i]=area(ad[i],cd[i],ac[i]);
}
float abd[100];
for(int i=0;i<100;i++){
abd[i]=area(ab[i],ad[i],bd[i]);
}
float bcd[100];
for(int i=0;i<100;i++){
bcd[i]=area(bc[i],cd[i],bd[i]);
}
float maxabc = abc[0];
for (int i = 0; i < 100; i++){
if (maxabc < abc[i])
maxabc = abc[i];
}
float minabc = abc[0];
for (int i = 0; i < 100; i++)
{
if (minabc > abc[i])
minabc = abc[i];
}
float maxadc = adc[0];
for (int i = 0; i < 100; i++)
{
if (maxadc < adc[i])
maxadc = adc[i];
}
float minadc = adc[0];
for (int i = 0; i < 100; i++)
{
if (minadc > adc[i])
minadc = adc[i];
}
float ans1=4*pow((maxabc+maxadc),2);
float ans2=4*pow((minabc+minadc),2);
cout<<round(ans1)<<” “<<round(ans2)<<endl;
return 0;
}
Single Lane Highway
from itertools import permutations import math # def get_count(d): # c=0 # for i in d: # c+=1 # return c n=int(input()) l=list(map(int,input().split())) cc=[] # d1=permutations(l,n1) # d2=permutations(l,n) # cc.append(get_count(d1)) # cc.append(get_count(d2)) s1=math.factorial(n)//math.factorial(n(n)) s2=math.factorial(n)//math.factorial(n(n1)) cc.append(s1) cc.append(s2) if(n%2==0): t=sum(cc)+2 else: t=sum(cc)1 print(“%.6f”%(t/cc[1]))
Binary Equivalent
#include using namespace std; #define ull unsigned long long int #define ll long long int #define loop(i,s,e) for(ll i=(s);i<(e);i++) #define rloop(i,s,e) for(ll i=(s);i>=(e);i–) #define scan(any) for(auto &i:any) cin>>i; #define print(any) for(auto i:any) cout<>n #define input2(a, b) int a,b;cin>>a>>b #define Max(a,b) ((a)>(b)?(a):(b)) #define Min(a,b) ((a)<(b)?(a):(b)) #define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++) #define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i–) #define mp make_pair #define pb push_back #define fi first #define se second #define vi vector#define pii pair#define piii pair,int> #define all(v) (v).begin(), (v).end() #define sz(x) (int)x.size() #define set(a,n) memset(a,n,sizeof(a)) void calc(int i,vi &v1,int siz,int s,int &tot) { if(i==siz) { if(s==0) tot++; return; } calc(i+1,v1,siz,s+v1[i],tot); calc(i+1,v1,siz,s,tot); } int main() { int n; cin>>n; vi v(n); scan(v); int m=0; for(int i=0;im) m=v[i]; } int count=0; while(m) { count++; m=m>>1; } vi v1(n,0); for(int i=0;i>1; } } int j=0; for(int i=0;i 0) { bin[i] = tot &1; tot = tot>>1; i++; } for (int j = count – 1; j >= 0; j–) cout << bin[j]; return 0; }
Path Through Graph
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl ‘n’
int get(int x)
{
for(int i=2;i*i<=x;i++)
{
if(x%i==0)return x/i;
}
return 1;
}
void sol()
{
int x,y;
cin>>x>>y;
if(x<y)swap(x,y);
if(x==y){cout<<0;return;}
map<int,int> m;
int c=0;
while(x!=1)
{
c++;
x=get(x);
m[x]=c;
}
c=0;
while(!m.count(y))
{
c++;
y=get(y);
}
cout<<c+m[y];
}
int32_t main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
sol();
return 0;