Skip to content

Commit 4403a2a

Browse files
.....
1 parent 1d8d669 commit 4403a2a

File tree

4 files changed

+234
-0
lines changed

4 files changed

+234
-0
lines changed

10X/Python/Array/BULB.py

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
'''
2+
Bulb
3+
There is a bulb. Just like other bulbs, this bulb can be either ON or OFF at a time. You can provide 3 types of instruction to the bulb-
4+
5+
"ON"-> turn the bulb on.(no matter the previous state)
6+
"OFF"-> turn the bulb off.(no matter the previous state)
7+
"Toggle"-> If the bulb was initially on, turn it off. If the bulb was initially off, turn it on.
8+
You provide the bulb with 'N' number of Queries, each containing either of the above 3 instructions. Count the number of times bulb was turned ON from a OFF position.(ON->OFF)
9+
10+
Note- Intially assume that the bulb was OFF.
11+
12+
Input
13+
First line of the input contains N, representing the number of instructions. The following N lines contain one of the 3 types of instructions "ON","OFF","Toggle".
14+
15+
Output
16+
Finally print the number of times the bulb was turned ON from a OFF position.
17+
18+
Example
19+
Input:
20+
21+
5
22+
23+
Toggle
24+
25+
Toggle
26+
27+
OFF
28+
29+
Toggle
30+
31+
ON
32+
33+
Output:
34+
35+
2
36+
37+
Explanation:
38+
39+
Intially : OFF
40+
41+
| BEFORE | INSTRUCTION | RESULT |
42+
------------------------------------
43+
| OFF | TOGGLE | ON |
44+
| ON | TOGGLE |OFF|
45+
| OFF | OFF | OFF |
46+
| OFF | TOGGLE | ON |
47+
| ON | ON | ON |
48+
As we can see that the bulb has been switched from OFF to ON 2 times once during the first(TOGGLE) instruction and then during the 4th(TOGGLE) instruction. So the output is 2
49+
'''
50+
'''
51+
n=int(input())
52+
a=[]
53+
for i in range(n):
54+
a.append(input())
55+
b=0
56+
count=0
57+
for j in range(n):
58+
if a[i]=="Toggle":
59+
if b==0:
60+
b=1
61+
count+=1
62+
else:
63+
b=0
64+
elif a[i]=="ON":
65+
if b==0:
66+
b=1
67+
count+=1
68+
else:
69+
b=1
70+
elif a[i]=="OFF":
71+
b=0
72+
print(count)
73+
'''
74+
n=int(input())
75+
a=[]
76+
for j in range(n):
77+
a.append(input())
78+
b=0
79+
count=0
80+
for i in range(n):
81+
if b==0 :
82+
if a[i]=="Toggle" or a[i]=="ON":
83+
b=1
84+
count+=1
85+
else:
86+
b=1
87+
elif b==1:
88+
if(a[i]=="Toggle") or (a[i]=="OFF") :
89+
b=0
90+
else:
91+
b=1
92+
print(count)
93+

10X/Python/Array/Parity Minimum.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'''
2+
Parity Minimum
3+
Description
4+
Given an array of length n which contains only positive integers, let S be the sum of the digits of the
5+
minimal element of the array.
6+
Return 0 if S is odd, otherwise return 1.
7+
8+
Input format
9+
First line contains a positive integer n, which denotes the number of elements in the array. This is
10+
followed by n lines each containing one integer denoting one element of the array.
11+
12+
Output format
13+
One line which is 0 or 1.
14+
15+
Sample input
16+
4
17+
34
18+
23
19+
1
20+
24
21+
Sample output
22+
0
23+
Explanation
24+
First line is 4, i.e. 4 elements in the array. Minimum element of the array is 1. Sum of digits of 1 is
25+
1 and as it is odd, the output is 0
26+
27+
Sample input
28+
2
29+
33
30+
44
31+
Sample output
32+
1
33+
Explanation
34+
First line is 2, i.e. 2 elements in the array. Minimum element of the array is 33. Sum of digits of 33
35+
is 6 and as it is even, the output is 1
36+
'''
37+
n=int(input())
38+
a=[]
39+
for i in range(n):
40+
a.append(int(input()))
41+
mi=min(a)
42+
su=0
43+
for i in str(mi):
44+
su+=int(i)
45+
if su%2==0:
46+
print(1)
47+
else:
48+
print(0)

10X/Python/Class/Person.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'''
2+
Person
3+
Define a class named Person, which should have the name and age as the properties. You don't need to worry about input/output and object of the class. The given template will take care of it.
4+
5+
The input will contain the name and age. The same will be printed in seperate lines as output.
6+
7+
Input
8+
One line containing two space seperated values, denoting name and age respectively.
9+
10+
Output
11+
Print name and age in newline each.
12+
13+
Example
14+
Input1:
15+
16+
Jonny 15
17+
Output1:
18+
19+
Jonny
20+
15
21+
'''
22+
### Define the required class here...
23+
class Person:
24+
def __init__(self, name, age):
25+
self.name=name
26+
self.age=age
27+
28+
29+
### DO NOT CHANGE ANYTHING BELOW THIS LINE
30+
31+
if __name__ == '__main__':
32+
33+
input_string = input().split()
34+
35+
p1 = Person(input_string[0], int(input_string[1]))
36+
37+
print(p1.name)
38+
print(p1.age)

10X/Python/String/MaxProduct.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'''
2+
Maximum Product
3+
link https://6793fdf6.widgets.sphere-engine.com/lp?hash=atbecI0dwg
4+
You are given a list of integers. Find the maximum product that can be obtained from multiplying adjacent integers in the list.
5+
6+
Input
7+
First line contains n, indicating the number of elements in the list, 2 <= n <= 10
8+
9+
This is followed by n lines each containing an integer
10+
11+
Output
12+
One integer indicating the maximum product achievable from adjacent elements of the list
13+
14+
Example
15+
Input:
16+
17+
4
18+
19+
1
20+
21+
3
22+
23+
4
24+
25+
10
26+
27+
Output:
28+
29+
40
30+
31+
Explination:
32+
33+
First line of input contains 4 indicating there are 4 elements in the list
34+
35+
The next four lines contain the elements of the list: 1,3,4,10
36+
37+
The possible products we can obtains is 1x3=3, 3x4=12, 4x10=40 where 40 is the maximum
38+
39+
40+
'''
41+
n=int(input())
42+
a=[]
43+
44+
for i in range(n):
45+
a.append(int(input()))
46+
ma=a[0]
47+
if n>1:
48+
for j in range(1,n):
49+
if ma<int(a[j-1]*a[j]):
50+
ma=int(a[j-1]*a[j])
51+
print(ma)
52+
elif n==0:
53+
print(0)
54+
else:
55+
print(ma)

0 commit comments

Comments
 (0)