A furnishing company is manufacturing a new collection of curtains. The curtains are of two colors aqua(a) and black (b). The curtains color is represented as a string(str) consisting of a’s and b’s of length N. Then, they are packed (substring) into L number of curtains in each box. The box with the maximum number of ‘aqua’ (a) color curtains is labeled. The task here is to find the number of ‘aqua’ color curtains in the labeled box.
Note :
If ‘L’ is not a multiple of N, the remaining number of curtains should be considered as a substring too. In simple words, after dividing the curtains in sets of ‘L’, any curtains left will be another set(refer example 1)
Example 1:
Input :
bbbaaababa -> Value of str
3 -> Value of L
Output:
3 -> Maximum number of a’s
Explanation:
From the input given above.
Dividing the string into sets of 3 characters each
Set 1: {b,b,b}
Set 2: {a,a,a}
Set 3: {b,a,b}
Set 4: {a} -> leftover characters also as taken as another set
Among all the sets, Set 2 has more number of a’s. The number of a’s in set 2 is 3.
Hence, the output is 3.
Example 2:
Input :
abbbaabbb -> Value of str
5 -> Value of L
Output:
2 -> Maximum number of a’s
Explanation:
From the input given above,
Dividing the string into sets of 5 characters each.
Set 1: {a,b,b,b,b}
Set 2: {a,a,b,b,b}
Among both the sets, set 2 has more number of a’s. The number of a’s in set 2 is 2.
Hence, the output is 2.
Constraints:
1<=L<=10
1<=N<=50
The input format for testing
The candidate has to write the code to accept two inputs separated by a new line.
First input- Accept string that contains character a and b only
Second input- Accept value for N(Positive integer number)
The output format for testing
The output should be a positive integer number of print the message(if any) given in the problem statement.(Check the output in Example 1, Example 2).
import java.util.*;
class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=0;
int n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
int c=1;
int d=sc.nextInt();
int f=sc.nextInt();
for(int i=0;i<n;i++){
if(d%2==0){
if(arr[i]%2!=0){
t=f*c;
c++;
}
}
else{
if(arr[i]%2==0){
t=f*c;
c++;
}
}
}System.out.println(t);
}
}
n=int(input())
ar=list(map(int,input().split()))
date=int(input())
fine=int(input())
e,o=0,0
for i in range(n):
if ar[i]%2==0:
e=e+1
else:
o=o+1
if date%2==0:
if o==0:
print(“0”)
else:
print(o*fine)
else:
if e==0:
print(“0”)
else:
print(e*fine)
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(“ENter how many people cross road”);
int n = sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<arr.length;i++) {
arr[i]=sc.nextInt();
}
System.out.println("Enter date");
int date= sc .nextInt();
System.out.println("Enter fine amount");
int fine= sc.nextInt();
int totalfine=0;
for(int i=0;i<arr.length;i++) {
if((date%2==0 && arr[i]%2!=0) ||(date%2!=0 && arr[i]%2==0)) {
totalfine +=fine;
}
}
System.out.println(totalfine);
}
TCS NQT Coding Question Day 4 Slot 1 – Question 2
import java.util.Scanner;
public class TotalFine {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int arr[] = new int[n];
for(int i=0; i<arr.length; i++) {
arr[i] = sc.nextInt();
}
int d = sc.nextInt();
int f = sc.nextInt();
sc.close();
boolean isEvenDate = d%2 == 0;
int totalFine = 0;
for(int x:arr) {
if(x%2 != 0 && isEvenDate || x%2 == 0 && !isEvenDate) {
totalFine += f;
}
}
System.out.println(totalFine);
}
}
def count_sundays(start_day, n):
# Mapping of days to their respective indices
day_map = {
‘sun’: 0,
‘mon’: 1,
‘tue’: 2,
‘wed’: 3,
‘thu’: 4,
‘fri’: 5,
‘sat’: 6
}
startindex=day_map[start_day]
first_sunday=7-startindex
if first_sunday>n:
return 0
else:
rem=n-first_sunday
return (1+(rem//7))
start_day = ‘sat’ # Starting day of the month
n_days = 30 # Number of days from the start of the month
result = count_sundays(start_day, n_days)
print(result)
n = int(input())
reg_num = []
for _ in range(n):
reg_num.append(int(input()))
d = int(input())
s = int(input())
total = 0
for num in reg_num:
if (d % 2 == 0 and num % 2 != 0) or (d % 2 != 0 and num % 2 == 0):
total += s
if total != 0 :
print(total)
else:
print(“0”)
import java.util.*;
public class main {
public static void main(String[] args) {
Scanner s= new Scanner(System.in);
System.out.print(“enter the number of arrays: “);
int n= s.nextInt();
int []arr=new int[n];
for(int i=0;i<arr.length;i++){
arr[i]=s.nextInt();
} int x=300;
int d=3;
int count=0;
if(d%2!=0){
for(int j=0;j<arr.length;j++){
if(j%2==0){
count++;
}
}
}else{
for(int j=0;j<arr.length;j++){
if(j%2!=0){
count++;
}
}
}
System.out.print(count*x);
}
}
TCS NQT Coding Question Day 4 Slot 1 – Question 2
Initial=list(map(int,input().split()))
Date=int(input(“Enter the date:”))
fine1=int(input(“Enter the Fine Amount:”))
fine=0
if Date%2==0:
for i in Initial:
if i==1:
fine+=0
elif i%2!=0 :
fine+=fine1
else:
for i in Initial:
if i==1:
fine+=0
elif i%2==0 :
fine+=fine1
print(“The Total Fine amount will be:”,fine)
Day 2 slot 1-Question 2
n=int(input(“Enter number”))
a=[]
for i in range(n):
a.append(int(input()))
d=int(input(“Enter date”))
fine=int(input(“Enter fine”))
count=0
if d%2==0:
temp=1
else:
temp=0
for i in a:
if temp==1:
if i%2!=0:
count+=fine
else:
if i%2==0:
count+=fine
print(count)
Kindly refer to our discord community for all your technical doubts.
Day 4 slot 1 question 1
N = int(input())
R = int(input())
def sum_of_digits(num):
sum_of_digits = 0
for i in str(num):
sum_of_digits += int(i)
return sum_of_digits
num_sum = sum_of_digits(N)
result = num_sum * R
result_sum = sum_of_digits(result)
final_result = result_sum if R!=0 else 0
print(final_result)