5Q) string trimmetris
Int get ans
// write your code here
18 11 J
13
14
16
30
int meint) (
Insyrm with stateles cin.tiele); cout 10 (8)
string inutise
Test case
HandsOnSquares Beauty
Summary
Questions
You me quen a square grid A of
You want to choose two non intersecting apuate sob-grids with no common row or column such that the sum of both sub grids is maximized.
Return the maximum possible sum
Input Format
The next line contains an integer. 4. denoting the number of columns in A
Each line i of the N subsequent lines (where N) contains N space separated integers each describing the row Ali
Constraints
1N500
-100 <= A[i][j] <= 100
Int get ans
// write your code here
18 11 J
13
14
16
30
int meint) (
Insyrm with stateles cin.tiele); cout 10 (8)
string inutise
Test case
HandsOnSquares Beauty
Summary
Questions
You me quen a square grid A of
You want to choose two non intersecting apuate sob-grids with no common row or column such that the sum of both sub grids is maximized.
Return the maximum possible sum
Input Format
The next line contains an integer. 4. denoting the number of columns in A
Each line i of the N subsequent lines (where N) contains N space separated integers each describing the row Ali
Constraints
1N500
-100 <= A[i][j] <= 100
6Q) You are given an integer N and a number
Let's define the cost of a string consisting of lowercase Latin letters as the cyelle distance between any two consecutive characters in that string,
Vadlaa
= Questions
For example, the cost of the string "abzy"
can be calculated as follows:
Minimum Cyclic Distance(a, b) + Minimum Cyclic Distance(b, z) +
Minimum CyclicDistance(z, v) = 1 + 2 + 4 = 7.
It is given that two strings of length N are different if their characters differ in at least one position from 1 to N.
Find the number of the distinct strings $ which satisfies the following two conditions
• The length of S is exactly equal to N.
• The cost of S is divisible by • The length of S is exactly equal to N.
The cost of S is divisible by K. vadlaa
Since the answer can be very large, print it modulo 109+7.
Input Format
The first line contains an N. denoting integ N the length of the required string.
The next line contains an integer, K. denoting the given number K.
Error
Constraints
2 <= N <= 10^5
.1 <= K <= 100
Sample Test Cases
Case 1
Input:
2
2
Output:
338
Explanation:
Given N= 2, K=2
In this case, one of the possible strings is "ac", also "ce". We can show that there are exactly "338" strings that satisfy the conditions.
So, answer is 338.
Let's define the cost of a string consisting of lowercase Latin letters as the cyelle distance between any two consecutive characters in that string,
Vadlaa
= Questions
For example, the cost of the string "abzy"
can be calculated as follows:
Minimum Cyclic Distance(a, b) + Minimum Cyclic Distance(b, z) +
Minimum CyclicDistance(z, v) = 1 + 2 + 4 = 7.
It is given that two strings of length N are different if their characters differ in at least one position from 1 to N.
Find the number of the distinct strings $ which satisfies the following two conditions
• The length of S is exactly equal to N.
• The cost of S is divisible by • The length of S is exactly equal to N.
The cost of S is divisible by K. vadlaa
Since the answer can be very large, print it modulo 109+7.
Input Format
The first line contains an N. denoting integ N the length of the required string.
The next line contains an integer, K. denoting the given number K.
Error
Constraints
2 <= N <= 10^5
.1 <= K <= 100
Sample Test Cases
Case 1
Input:
2
2
Output:
338
Explanation:
Given N= 2, K=2
In this case, one of the possible strings is "ac", also "ce". We can show that there are exactly "338" strings that satisfy the conditions.
So, answer is 338.
👍3
7Q) you are given a string S with N characters a string T with M characters and an integer K
you can perform the following operation on s atmost K times
change a character at some index in the string to any other character
find the count of maximum number of subsegments in the S that have T as subsequence after applying the operation
Sample input
3
1
1
abc
d
sample output
1
explanation
Given N=3 M=1 K=1 S=abc T=d
we can change s[1] to d and the ans will be 1
give a code such that output for the given input is 1
sample input 2
3
1
1
abc
b
sample output 2
2
you can perform the following operation on s atmost K times
change a character at some index in the string to any other character
find the count of maximum number of subsegments in the S that have T as subsequence after applying the operation
Sample input
3
1
1
abc
d
sample output
1
explanation
Given N=3 M=1 K=1 S=abc T=d
we can change s[1] to d and the ans will be 1
give a code such that output for the given input is 1
sample input 2
3
1
1
abc
b
sample output 2
2
👍3
8Q) You are given an integer N and a number K.
Let's defind the cost of a string consisting of lowercase latin letters as the cyclic distance between any two consecutive characters in string
For example the cost of the string "abzv" can be calculated as follow:
MinimumCyclicDistance(a,b)+
MinimumCyclicDistance(b,z)+
MinimumCyclicDistance(z,v)= 1+2+4=7
It is given that two strings of length N are different if their character differ at least one position from 1 to N
Find the number of the distinct string S which satisfies the following two conditions:
The length of S is exactly equal to N
The code of S is divisible by K
Since the answer can be very large print it modulo 10 to the power 9 + 7
Input format
The first line contains an integer N denoting the length of the requires string.
The next line contains an integer K denoting the given number K
Constraints
2<=N <= 10^5
1<=K<=100
Sample test case
Case 1
Input
2
2
Output
338
Explanation:
In this case, one of the possible strings is "ac", also "ce".
We can show that there Re exactly*338" strings that satisfy the conditions
So the answer is 338.
Case 2;
Input:
3
1
Output
17576
Explanation:
Given N =3, K= 1
In this sample, since every number is divisible by "1", then any string of length "3" is "26 * 26 * 26= 17576".
Case 3:
Input :
2
13
Output
52
Explanation:
In this case, one of the possible strings is"an", also "cp"
We can show that there are exactly "52" strings that satisfy the conditions
Let's defind the cost of a string consisting of lowercase latin letters as the cyclic distance between any two consecutive characters in string
For example the cost of the string "abzv" can be calculated as follow:
MinimumCyclicDistance(a,b)+
MinimumCyclicDistance(b,z)+
MinimumCyclicDistance(z,v)= 1+2+4=7
It is given that two strings of length N are different if their character differ at least one position from 1 to N
Find the number of the distinct string S which satisfies the following two conditions:
The length of S is exactly equal to N
The code of S is divisible by K
Since the answer can be very large print it modulo 10 to the power 9 + 7
Input format
The first line contains an integer N denoting the length of the requires string.
The next line contains an integer K denoting the given number K
Constraints
2<=N <= 10^5
1<=K<=100
Sample test case
Case 1
Input
2
2
Output
338
Explanation:
In this case, one of the possible strings is "ac", also "ce".
We can show that there Re exactly*338" strings that satisfy the conditions
So the answer is 338.
Case 2;
Input:
3
1
Output
17576
Explanation:
Given N =3, K= 1
In this sample, since every number is divisible by "1", then any string of length "3" is "26 * 26 * 26= 17576".
Case 3:
Input :
2
13
Output
52
Explanation:
In this case, one of the possible strings is"an", also "cp"
We can show that there are exactly "52" strings that satisfy the conditions
👍1
9Q) There is a flower shop contains n flowers in a row each cover can be followed with one of the following colours that will red green white or yellow
You are given a string S of length N where S[i] is either "R", "G", "B", or "Y", representing the color of the ith flower.
Each flower has a beauty associated with it, which is given in an array flower. B of length N, where B[i] is the beauty of the ith
A range of flowers [L, R] is called good if the following is true:
• The number of red flowers in that range equals the number of green flowers.
• The number of blue flowers equals the number of yellow flowers.
Your task is to choose zero or more non-intersecting good ranges of flowers such that the sum of the beauty of all the flowers in all the ranges is as maximum as possible.
The first line contains an integer, N, denoting the number of elements in B.
The next line contains a string, S, denoting the given string.
Each line i of the N subsequent lines (where 0 ≤ i < N) contains an integer describing b[j]
1 <= N <= 10 ^ 5
N <= len(S) <= N
1 <= B[i] <= 10 ^ 4
Case 1
Input
4
RGBY
1
1
1
1
Output:
4
Given N = 4, S = "RGBY", B = [1, 1, 1, 1].
In this sample sum equals to 4. we choose the interval [1, 4] with beauty
Sum equals to 4
Input
5
BYRRG
2
2
2
2
2
Output:
8
Explanation
Given N = 5, S = "BYRRG", B = [2, 2, 2, 2, 2].
In this sample we will choose two intervals , 5]. With sum beauty equals to 4 in each interval. [1,2], [4
,5]
With sum beauty equals to 4 in each interval
Input:
12
13
BYRYRGBY
4
2
5
14
15
16
17
10
4
2
1
9
18
19
20
21
Output:
22
23
23
Explanation:
Given N = 8, S = "BYRYRGBY", B = [4, 2, 5, 10, 4, 2, 1, 9].
Case 1
In this sample the intervals are [1, 2], [4,7]
Input
The final beauty sum is 6 + 17 = 23.
import java.io.*;
import java.util.*;
import java.lang.Math;
public class Solution { public static int GetMaximumSum(int N, String S, List<Integer> B) {
// Write your code here
}
public static void main(String[] args) { Scanner scan = new Scanner(System.in);
int N = Integer.parseInt(scan.nextLine().trim());
String S = scan.nextLine();
List<Integer> B = new ArrayList<>(N);
for(int j=0; j<N; j++) {
B.add(Integer.parseInt(scan.nextLine().trim()));
}
int result = GetMaximumSum (N, S, B);
System.out.println(result);
}
}
You are given a string S of length N where S[i] is either "R", "G", "B", or "Y", representing the color of the ith flower.
Each flower has a beauty associated with it, which is given in an array flower. B of length N, where B[i] is the beauty of the ith
A range of flowers [L, R] is called good if the following is true:
• The number of red flowers in that range equals the number of green flowers.
• The number of blue flowers equals the number of yellow flowers.
Your task is to choose zero or more non-intersecting good ranges of flowers such that the sum of the beauty of all the flowers in all the ranges is as maximum as possible.
The first line contains an integer, N, denoting the number of elements in B.
The next line contains a string, S, denoting the given string.
Each line i of the N subsequent lines (where 0 ≤ i < N) contains an integer describing b[j]
1 <= N <= 10 ^ 5
N <= len(S) <= N
1 <= B[i] <= 10 ^ 4
Case 1
Input
4
RGBY
1
1
1
1
Output:
4
Given N = 4, S = "RGBY", B = [1, 1, 1, 1].
In this sample sum equals to 4. we choose the interval [1, 4] with beauty
Sum equals to 4
Input
5
BYRRG
2
2
2
2
2
Output:
8
Explanation
Given N = 5, S = "BYRRG", B = [2, 2, 2, 2, 2].
In this sample we will choose two intervals , 5]. With sum beauty equals to 4 in each interval. [1,2], [4
,5]
With sum beauty equals to 4 in each interval
Input:
12
13
BYRYRGBY
4
2
5
14
15
16
17
10
4
2
1
9
18
19
20
21
Output:
22
23
23
Explanation:
Given N = 8, S = "BYRYRGBY", B = [4, 2, 5, 10, 4, 2, 1, 9].
Case 1
In this sample the intervals are [1, 2], [4,7]
Input
The final beauty sum is 6 + 17 = 23.
import java.io.*;
import java.util.*;
import java.lang.Math;
public class Solution { public static int GetMaximumSum(int N, String S, List<Integer> B) {
// Write your code here
}
public static void main(String[] args) { Scanner scan = new Scanner(System.in);
int N = Integer.parseInt(scan.nextLine().trim());
String S = scan.nextLine();
List<Integer> B = new ArrayList<>(N);
for(int j=0; j<N; j++) {
B.add(Integer.parseInt(scan.nextLine().trim()));
}
int result = GetMaximumSum (N, S, B);
System.out.println(result);
}
}
👍3❤1