Skip to content

Commit 0b730de

Browse files
Previous Unsolved
1 parent f090c96 commit 0b730de

9 files changed

+572
-0
lines changed

10X/Python/Array/Choclate Bars.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'''
2+
Chocolate Bars
3+
There are N chocolates denoted by array A where A[i] is the length of the i-th chocolate. Alice can
4+
melt each chocolate and then convert it into a chocolate whose length is any divisor of the number A[i].
5+
So, a chocolate of length A[i] can be converted into X different types of chocolate where X is the count
6+
of divisors of the number A[i]. So you need to count the total unordered pair (i, j) of chocolates such
7+
that their X value is same.
8+
9+
Input
10+
The first line contains an integer N as input denoting the total number of elements in the array A.
11+
The next line contains N space-separated integers that denote the elements of the array A.
12+
13+
Output
14+
In the output, print the total number of ways as mentioned in the statement.
15+
16+
Example
17+
Input:
18+
19+
3
20+
21+
2 3 4
22+
23+
Output:
24+
25+
1
26+
27+
Explanation
28+
X values of each number .
29+
30+
A[1] = 2 , divisors of A[1] are 1, 2.Thus X value of A[1] is 2.
31+
32+
similarly, A[2] = 3, divisors of A[2] are 1, 3.Thus X value of A[2] is 2.
33+
34+
A[3] = 4, divisors of A[3] are 1, 2, 4. Thus X value of A[3] is 3.
35+
36+
Thus we have only one pair (1, 2) for which X value is 2.
37+
38+
'''
39+
import math
40+
41+
def factor(n):
42+
count=0
43+
for i in range(1,1+int(math.sqrt(n))):
44+
if n%i==0:
45+
count+=1
46+
if n//i!=i:
47+
count+=1
48+
return count
49+
50+
def result(ar,n):
51+
d={}
52+
for i in ar:
53+
x=factor(i)
54+
if x in d:
55+
d[x]+=1
56+
else:
57+
d[x]=1
58+
res=0
59+
for x in d:
60+
res+=(d[x]*(d[x]-1))//2
61+
return res
62+
63+
64+
n=int(input())
65+
ar=[int(x) for x in input().split()]
66+
print(result(ar,n))
67+
68+
# Help.....

10X/Python/Array/Common_Alphabet.py

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'''
2+
Common Alphabets
3+
Given list of strings. The task is to find the frequency of the elements which are common in all strings
4+
given in the list of strings.
5+
6+
Input:
7+
First line contains N, number of strings.
8+
9+
Next N lines contians a string in each line.
10+
11+
Output:
12+
N linese each line contains an alphabet and it's frequency in sorted order for each of the input string.
13+
14+
alphabet and the frequency are separated by a space
15+
16+
Problem Constraints:
17+
1<=A.length<=500
18+
19+
1<=A[0].length<=100
20+
21+
Examples:
22+
Input :
23+
24+
3
25+
26+
gefgek
27+
28+
gfgk
29+
30+
kinfgg
31+
32+
Output :
33+
34+
f 1
35+
36+
g 2
37+
38+
k 1
39+
40+
Explanation :
41+
f occurs once in all Strings.
42+
43+
g occurs twice in all the strings.
44+
45+
k occurs once in all string.
46+
47+
Output is in ascending order
48+
49+
'''
50+
from typing import Counter
51+
n=int(input())
52+
arr=[]
53+
for i in range(n):
54+
arr.append(input())
55+
dic=Counter(arr[0])
56+
for i in range(1,n):
57+
d=Counter(arr[i])
58+
for i in dic:
59+
if d[i]==0:
60+
dic[i]=-1
61+
else:
62+
dic[i]=min(dic[i],d[i])
63+
for i in sorted(dic):
64+
if(dic[i]>0):
65+
print(i+" "+str(dic[i]))
66+

10X/Python/Array/FINDING HELLO.PY

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'''
2+
Find Hello
3+
You are given a string. You are supposed to find if "hello" exists in the given string as a substring. See explanation for better understanding. If "hello" exists print "Yes" else print "No".
4+
5+
Note: length of string is greater than 0.
6+
7+
Input
8+
First line contains n number of strings for which you need to check. After this n lines will follow. Each containing a string.
9+
10+
Output
11+
Print "Yes" or "No".
12+
13+
Input:
14+
15+
2
16+
17+
Academy
18+
19+
ramhellolaxman
20+
21+
Output:
22+
23+
No
24+
25+
Yes
26+
27+
Explanation
28+
Testcase 1: There is no hello in the word Academy.
29+
30+
Testcase 2: hello starts at index 3 and ends at 7.
31+
'''
32+
'''
33+
def Finding_Hello(s):
34+
l=len(s)
35+
w="hello"
36+
f=False
37+
for i in range(0,(len(s)-4)):
38+
if w==s[i:i+5]:
39+
return True
40+
return f
41+
42+
for _ in range(int(input())):
43+
print(Finding_Hello(input()))
44+
45+
'''
46+
def Finding_Hello(s,target):
47+
if target in s:
48+
return "Yes"
49+
else:
50+
return "No"
51+
target="hello"
52+
for _ in range(int(input())):
53+
print(Finding_Hello(input(),target))

10X/Python/Array/IsAngram.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"""
2+
IS Anagram
3+
You are given two strings A and B, you have to check whether they are anagrams of one another. An anagram
4+
is a word that can be obtained by rearranging the characters of the initial word.
5+
6+
Note- DO NOT use the inbuilt sort function at any stage of the code
7+
8+
Input
9+
First line contains the string A and second line contains the string B 1<=len(A),len(B)<=2000
10+
11+
Output
12+
Print "1" if they are anagrams and print "0" if they are not anagrams
13+
14+
Example
15+
Input:
16+
17+
ABABCD
18+
19+
AABBCD
20+
21+
Output:
22+
23+
1
24+
25+
explanation
26+
27+
Since ABABCD can be rearranged to get AABBCD we print "1" as output
28+
"""
29+
'''
30+
s1=input()
31+
s2=input()
32+
d1={}
33+
d2={}
34+
if len(s1)==len(s2):
35+
for i in range(len(s1)):
36+
j=s1[i]
37+
if j in d1:
38+
d1[j]+=1
39+
else:
40+
d1[j]=1
41+
for i in range(len(s2)):
42+
j=s2[i]
43+
if j in d2:
44+
d2[j]+=1
45+
else:
46+
d2[j]=1
47+
if sorted(d1)==sorted(d2):
48+
print(1)
49+
else:
50+
print(0)
51+
else:
52+
print(0)
53+
54+
'''
55+
#######################################
56+
s1=input()
57+
s2=input()
58+
d1={}
59+
d2={}
60+
if len(s1)==len(s2):
61+
for i in range(len(s1)):
62+
j=s1[i]
63+
if j in d1:
64+
d1[j]+=1
65+
else:
66+
d1[j]=1
67+
for i in range(len(s2)):
68+
j=s2[i]
69+
if j in d2:
70+
d2[j]+=1
71+
else:
72+
d2[j]=1
73+
#if sorted(d1)==sorted(d2):
74+
if d1==d2:
75+
print(d1)
76+
print(d2)
77+
print(1)
78+
else:
79+
print(0)
80+
else:
81+
print(0)
82+

10X/Python/Array/Sport_sum.py

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
"""
2+
Sports Stats
3+
Max likes football very much. In order to check the popuplarity of the game, he decided to talk to random people and ask them about their favourite game and note it down in a list.
4+
5+
Given a list of name of people and their favourite sport, help Max in finding the sport liked by most of the people, and also how many people like football.
6+
7+
He could have met same people more than once, he will only count response of his first meet with any person.
8+
9+
Note : Name of person as well as sport is a single string in lowercase. Length of name of people as well as sport is less than 11.
10+
11+
Input
12+
First line will contain no of entries in the list. i.e. N Next N lines will contain two strings, person's name and sports he like.
13+
14+
Output
15+
In first ine, name of sport liked by most no of people (In case of more than one games is liked by highest no of people, output the first one in lexicographical order). In second line, no of people having football as their favourite game.
16+
17+
Example
18+
Input:
19+
20+
7
21+
22+
abir cricket
23+
24+
aayush cricket
25+
26+
newton kabaddi
27+
28+
abhinash badminton
29+
30+
sanjay tennis
31+
32+
abhinash badminton
33+
34+
govind football
35+
36+
Output:
37+
38+
cricket
39+
40+
1
41+
42+
Explanation
43+
2 people likes cricket, ans so it liked by maximum people. 1 person has football as his favourite sport
44+
"""
45+
'''
46+
d={}
47+
max=0
48+
sports=""
49+
for _ in range(int(input())):
50+
data=input().split(" ")
51+
d[data[0]]=data[1]
52+
for key in d:
53+
count=0
54+
for j in d:
55+
if d[key]==d[j]:
56+
#if key==j:
57+
count=count+1
58+
if count>max:
59+
max=count
60+
sports=d[key]
61+
print(sports)
62+
find="football"
63+
count=0
64+
for key in d:
65+
if d[key]==find:
66+
count+=1
67+
print(count)
68+
69+
#80%
70+
'''
71+
d={}
72+
max=0
73+
# sports=""
74+
nd={}
75+
sp=""
76+
for _ in range(int(input())):
77+
data=input().split(" ")
78+
d[data[0]]=data[1]
79+
for i in d:
80+
j=d[i]
81+
if j in nd:
82+
nd[j]+=1
83+
else:
84+
nd[j]=1
85+
for i in sorted(nd):
86+
if nd[i]>max:
87+
max=nd[i]
88+
sp=i
89+
print(sp)
90+
# for i in d:
91+
# if d[i]==sp:
92+
# sports=d[i]
93+
find="football"
94+
count=0
95+
for key in d:
96+
if d[key]==find:
97+
count+=1
98+
print(count)

0 commit comments

Comments
 (0)