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).
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)
Day 2 slot 1-Question 2
N = int(input())
A = [int(input()) for i in range(N)]
D = int(input())
Fine = int(input())
count_e,count_o = 0,0
for i in A:
if i%2 == 0:
count_e +=1
else:
count_o +=1
result = count_e * Fine if D%2!=0 else count_o * Fine
print(result)
Day 3 slot 2 -Question 2
def factorial(Num):
fact = 1
for i in range(1,Num+1):
fact =fact * i
return fact
N = int(input())
print(factorial(N-1)*2)
Day 3 slot 2 -Question 1
L=int(input())
N = int(input())
A = [input() for i in range(N)]
count = 0
max_count = 0
itterator = 0
for i in A:
if i == “a”:
count+=1
itterator+=1
if itterator % L == 0:
max_count = max(max_count,count)
count = 0
else:
max_count = max(max_count,count)
print(max_count)
Day 3 Slot 2 – Question 1
python code
a_count = 0
string = input()
L = int(input())
prev_count = 0
curr_count = 0
count = 0
for char in string:
if count == L:
count = 0
prev_count = max(prev_count, curr_count)
curr_count = 0
if char == ‘a’:
curr_count += 1
count += 1
# print(count, char, curr_count, prev_count)
print(max(curr_count, prev_count))
a_count = 0
string = input()
L = int(input())
prev_count = 0
curr_count = 0
count = 0
for char in string:
if count == L:
count = 0
prev_count = max(prev_count, curr_count)
curr_count = 0
if char == ‘a’:
curr_count += 1
count += 1
prev_count = max(prev_count, curr_count) # Update prev_count after the loop ends
print(prev_count)
Day 3 Slot 2 – Question 2
Python code
def factorial(N):
if N == 1:
return 1
return N*factorial(N-1)
N = int(input())
print(factorial(N-1)*2)
Day 4 Slot 1 – Question 2
Python code
`
N = int(input())
odd_count = 0
even_count = 0
for _ in range(N):
n = int(input())
if n%2 == 0:
even_count += 1
else:
odd_count += 1
D = int(input())
X = int(input())
result = X
result *= odd_count if D%2 == 0 else even_count
print(result)
`
#include
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n];
int d,x;
int cnt=0;
int fine=0;
cout<<"Enter date and fine amount"<>d>>x;
cout<<"Enter the array elements"<<endl;
for(int i=0;i>arr[i];
if(d%2==0)
{
if(arr[i]%2!=0)
{
cnt++;
}
}
else if(d%2!=0)
{
if(arr[i]%2==0)
{
cnt++;
}
}
}
fine=cnt*x;
cout<<"The fine amount to be payed is "<<fine<<endl;
return 0;
}
Problem Statement –
A chocolate factory is packing chocolates into the packets. The chocolate packets here represent an array of N number of integer values. The task is to find the empty packets(0) of chocolate and push it to the end of the conveyor belt(array).
#include
#include
#define MAX 100
using namespace std;
int stack[MAX];
int top=-1;
void push(int);
int pop();
int isEmpty();
int isFull();
void push(int a)
{
if(isFull())
{
cout<<"stack overflow"<<endl;
exit(1);
}
top++;
stack[top]=a;
}
int pop()
{
int a;
if(isEmpty())
{
cout<<"stack underflow"<<endl;
exit(1);
}
a=stack[top];
top–;
return a;
}
int isEmpty()
{
if(top==-1)
return 1;
else
return 0;
}
int isFull()
{
if(top==MAX-1)
return 1;
else
return 0;
}
void new_arr(int arr[],int arr1[],int n)
{
int i,j=0;
int value;
for(i=0;i<n;i++)
{
value=arr[i];
switch(value)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
arr1[j++]=arr[i];
break;
case 0:
push(arr[i]);
break;
}
}
while(!isEmpty())
arr1[j++]=pop();
}
int main() {
int arr[MAX];
int n;
cout << "Enter the number of integers: " <>n;
// store input from user to array
cout<<"enter the elements:"<<endl;
for (int i = 0; i > arr[i];
}
int arr1[n];
new_arr(arr,arr1, n);
cout << "The final array is: "<<endl;
// print array elements
for (int k = 0; k< n; ++k) {
cout << arr1[k] << " ";
}
return 0;
}
TCS NQT Coding Question Day 4 Slot 1 – Question 2
#python code
n=int(input())
list1 = []
for i in range(n):
list1.append(int(input()))
even_count, odd_count = 0,0
d = int(input())
x = int(input())
# iterating each number in list
for num in list1:
# checking condition
if num % 2 == 0:
even_count += 1
else:
odd_count += 1
if d%2==0:
print(x*odd_count)
else:
print(x*even_count)
for c++
#include
using namespace std;
int main()
{
int n,d,x,a[10],amount=0,c=0,k=0;
cout<>n;
cout<<"enter the elements :\n";
for(int i=0;i>a[i];
if(a[i]%2==0)
{
c++;
}
else
k++;
}
cout<>d;
cout<>x;
if(d%2==0)
{
amount =k*x;
}
else
amount=c*x;
cout<<"total fine collected :"<<amount;
return 0;
}
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int d,x,n;
System.out.println(“enter date “);
d=sc.nextInt();
System.out.println(“enter fine “);
x=sc.nextInt();
System.out.println(“enter size “);
n=sc.nextInt();
int arr[]= new int[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
int f=0;
if(d%2==0)
{
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
f++;
}
int res=f*x;
System.out.println(res);
}
else if(d%2!=0)
{
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
f++;
}
int res=f*x;
System.out.println(res);
}
// int res=f*x;
// System.out.println(f);
}