Programming Ans
Programming Ans
are 2 teams playing against each other. Only one team can be the winning team of the
tournament. The value of N is passed as the input to the program. The program must print the
maximum number of matches a winning team can play as the output. If the number of teams
participating in the tournament is less than 2, the program must print the string value MATCH NOT
The function/method countFascinatingNumbers accepts two arguments start and end representing two
numbers, where start <= end. The function/method countFascinatingNumbers must return the count of
fascinating numbers in the range from start to end. A fascinating number is defined as a number that
has odd number of factors. Your task is to implement the function countFascinatingNumbers so that the
program runs successfully.
Boundary Condition:
Example Input/Output 1:
Input:
22 26
Output:
Explanation:
Here start = 22 and end = 26.
23 -> 1, 23 (2 factors)
25 -> 1, 5, 25 (3 factors)
Example Input/Output 2:
Input:
10 150
Output:
A clothing company is manufacturing a new collection of clothes. The clothes are of two colors red(r)
and blue(b). The colors of the clothes are represented as a string S consisting of r's and b's of length L.
Then they are packed into boxes, where each box contains N number of clothes. If L is not a multiple N
then the remaining clothes are packed into the last box. The box with the maximum number of blue
color clothes is labeled. The string value S and the integer value of N are passed as the input. The
program must print the number of blue color clothes in the labeled box as the output.
Packing Balls - Maximum Boxes
The program must accept two integers R and W as the input. R indicates the number of red
balls and W indicates the number of white balls in a shop. The shopkeeper wants to pack the balls
The program must print the maximum number of boxes he needs to pack the balls.
Boundary Condition(s):
Input Format:
Output Format:
The first line contains an integer representing the maximum number of boxes he needs to pack the
balls.
Example Input/Output 1:
Input:
35
Output:
Explanation:
Input:
66
Output:
Example Input/Output 3:
Input:
10 5
Output:
There are N boxes arranged in a row. Each box contains a certain number of fruits. The number of
fruits in each box is passed as the input to the program. A boy wants to collect a maximum number
- He must select the K consecutive boxes but the Xth box must be in his list.
The values of K and X are passed as the input. The program must print the maximum number of
Boundary Condition(s):
1 <= X, K <= N
Input Format:
The second line contains N integer values separated by a space representing the number of fruits in
the N boxes.
Output Format:
The first line contains the maximum number of fruits that the boy can collect.
Test case:
Input:
22 1 25 20 6 5 4
54
Output:
56
Explanation:
25 20 6 5 -> 56
20 6 5 4 -> 35
The maximum number of fruits that the boy can collect is 56. So 56 is printed as the output.
Test case:
Input:
14 25 32 5 15 11 13 23 16
55
Output:
91
Test case:
Input:
25
487 779 1 158 255 406 454 667 643 896 150 435 259 473 641 908 77 407 694 374 278 598 33 348 157
19
Expected Output:
3850
method1:
n=int(input())
lis=list(map(int,input().split()))
x,k=map(int,input().split())
st=x-k
if st<0:
st=0
en=x+k-1
if en>n:
en=n
m=-1
for i in range(st,en-k+1):
s=sum(lis[i:i+k])
if m<s:
m=s
print(m)
method2:
n = int(input())
x, k = map(int, input().split())
# Subtract 1 from x because Python uses 0-based indexing
x -= 1
start = x - k + 1
if start < 0:
start = 0
end = x + k
if end > n:
end = n
ma = -1
s = sum(lis[i:i + k])
if ma < s:
ma = s
print(ma)