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
10Q) You are given a tree with N nodes numbered from 1 to N
You are also given an array A of length N where A[i] denotes the value of node 1.
It is given that the MEX (minimum excluded) of a set is the smallest non-negative integer that does not belong to the set.
For instance: The MEX of "(2, 1)" is "0", because "0" does not belong to the set. The MEX of "(3, 1, 0)" is "2", because "0" and "1" belong to the set, but "2" does not.
Let's define the beauty of a tree as the MEX of the values assigned to the nodes of that tree.
Case 1
Your need to choose exactly one edge from the given tree and then divide the tree into two parts (two trees) such that
The sum of the beauties of the two resulting trees is the maximum possible.
Return this sum.
Input Format
The first line contains an integer, N, denoting the number of elements in A.
The next line contains an integer, M, denoting the number of rows in edges.
The next line contains an integer, C, denoting the number of columns in edges.
Each line i of the M subsequent lines (where 0 <= i < M) contains C space separated integers each describing the row edges[i].
Each line i of the N subsequent lines. (where 1 <= i \le N) contains an integer describing A[i].
Constraints
2 <= N <= 10 ^ 6
N - 1 <= M <= N - 1
2 <= C <= 2
1 <= edges[i][j] <= N
0<= A[i]<= N
P
Sample Test Cases
Case 1
Questions
Input:
3
2
2
12
13
0
1
2
Output: 2
Explanation:
Here, N-3, M-2, C-2, edges-[[1,2], [1,3]] and A- [0, 1, 2]
In this sample, if we cut the edge between node "1" and node "3", one of the resulting subtree will has a beauty of "2" and the other a beauty zero.
So the answer is "2 + 0 = 2".
Case 2
Input:
4
3
2
12
13
24
0
2
1
0
Case 3
Input:
6
5
2
12
23
34
45
56
1
0
2
021
1
Output: 6
Explanation:
Here, N=6, M=5, C=2, edges=[[1,2], [2,3], [3,4], [4,5], [5,6]] and A=[1,, 2, 0, 2, 1]
In this sample, if we cut the edge between node "3" and, node "4", one of the resulting subtree will has a beauty of "3" and the other a beauty of "3".
So, the answer is "3 + 3 = 6".
Output: 4
Explanation:
Here, N = 4 , M = 3 , C = 2 , edges=[[1,2], [1,3], [2, 4] ] and A = [0, 2, 1, 0]
In this sample, if we cut the edge between node "2" and node "4", one of the resulting subtree will has a beauty of "3" and the other a beauty of "1".
So, the answer is 3 + 1 =4^ prime prime .
You are also given an array A of length N where A[i] denotes the value of node 1.
It is given that the MEX (minimum excluded) of a set is the smallest non-negative integer that does not belong to the set.
For instance: The MEX of "(2, 1)" is "0", because "0" does not belong to the set. The MEX of "(3, 1, 0)" is "2", because "0" and "1" belong to the set, but "2" does not.
Let's define the beauty of a tree as the MEX of the values assigned to the nodes of that tree.
Case 1
Your need to choose exactly one edge from the given tree and then divide the tree into two parts (two trees) such that
The sum of the beauties of the two resulting trees is the maximum possible.
Return this sum.
Input Format
The first line contains an integer, N, denoting the number of elements in A.
The next line contains an integer, M, denoting the number of rows in edges.
The next line contains an integer, C, denoting the number of columns in edges.
Each line i of the M subsequent lines (where 0 <= i < M) contains C space separated integers each describing the row edges[i].
Each line i of the N subsequent lines. (where 1 <= i \le N) contains an integer describing A[i].
Constraints
2 <= N <= 10 ^ 6
N - 1 <= M <= N - 1
2 <= C <= 2
1 <= edges[i][j] <= N
0<= A[i]<= N
P
Sample Test Cases
Case 1
Questions
Input:
3
2
2
12
13
0
1
2
Output: 2
Explanation:
Here, N-3, M-2, C-2, edges-[[1,2], [1,3]] and A- [0, 1, 2]
In this sample, if we cut the edge between node "1" and node "3", one of the resulting subtree will has a beauty of "2" and the other a beauty zero.
So the answer is "2 + 0 = 2".
Case 2
Input:
4
3
2
12
13
24
0
2
1
0
Case 3
Input:
6
5
2
12
23
34
45
56
1
0
2
021
1
Output: 6
Explanation:
Here, N=6, M=5, C=2, edges=[[1,2], [2,3], [3,4], [4,5], [5,6]] and A=[1,, 2, 0, 2, 1]
In this sample, if we cut the edge between node "3" and, node "4", one of the resulting subtree will has a beauty of "3" and the other a beauty of "3".
So, the answer is "3 + 3 = 6".
Output: 4
Explanation:
Here, N = 4 , M = 3 , C = 2 , edges=[[1,2], [1,3], [2, 4] ] and A = [0, 2, 1, 0]
In this sample, if we cut the edge between node "2" and node "4", one of the resulting subtree will has a beauty of "3" and the other a beauty of "1".
So, the answer is 3 + 1 =4^ prime prime .
👍2
11Q) Bob was walking his dog in the village.
Unfortunately he got lost in an orange grove and wants to reach the exit.
The grove can be represented as a 2D grid consisting of N rows and M columns such that
• The rows are number from 1 to N from top to down.
The columns are numbered from 1 to M from left to right.
Each cell (i, j) of the grid has either of the following
• An orange tree with A[i][j] oranges.
• An infinite number of lanterns.
It is given that cells with lanterns will be have value 0.
the beginning, Bob is at cell (1, 1) and he wants to reach the exit at cell (N, M). He can move either right or down in the grove. As Bob reaches a cell (i, j), he will eat some amount of oranges from the tree in that cell (at most A[i][j]). In case this cell has lanterns, he will not be able to eat any oranges.
Bob wants to mark the path he's following with lanterns, so when he reaches a cell he will send his dog to some cell which has lanterns then the dog will pick up a lantern and comeback to Bob to put the lantern in that cell
The dog can move up, down, left and right in the grid, and the dog travels 1 kilo meter when moving from one cell to another.
When Bob moves from one cell to another, his dog will follow him as well.
Bob defines the profit of a path that leads him to
the exit as the difference between the total amount
of oranges he could eat along that path and theof oranges he could eat along that path and the total distance in kilo meters his dog traveled along that path
Find the maximum profit of a path that leads Bob to the exit of the grove
The distance the dog travels with Bob when Bob moves from cell to another is not included (only the distance of getting lanterns is calculated for the dog)
• Bob will put lanterns in every cell of the path, including the starting and ending cells.
He can also move to a cell which has lanterns, but this will not affect the amount of oranges.
It is guaranteed that there is at least one cell with lanterns.
Input Format
The first line contains an integer, N, denoting the number of rows in Grid.
The next line contains an integer, M, denoting the number of columns in Grid.
Each line i of the N subsequent lines (where 0≤i< N) contains M space separated integers each describing the row Grid[i].
Constraints
1 <= N <= 10^5
1 <= M <= 10^5
0 <= Grid[i][j] <= 10^9
Sample Test Cases
Case 1
Input:
1
1
0
Output:
0
Explanation:
N=1, M-1, Grid=0
Bob is already at the ending cell, bob will not eat oranges and the dog will not travel anywhere since this cell has lanterns.
So the answer is 0.
Output:
2
Explanation:
N-2, M-2, Grid-[[3,0], [5,2]]
In the beginning, Bob will eat 3 oranges at cell (1, 1) then he will send his dog to cell (1, 2) to get a lantern, the dog will travel 2kms back and forth.
Then Bob will move with dog to cell (2, 1), eat 5 oranges and send his dog to cell (1, 2) again, the dog will travel 4kms (2kms for going and 2 for returning).
Finally Bob will move with the dog to the exit cell (2, 2), eat 2 oranges and send his dog to cell (1, 2), the dog will travel 2kms to get the lantern.
The final answer is 3-2 + 5-4 + 2-2 = 2.
Output:
3
Explanation:
N-3, M-3, Grid=[[5,4,0], [1,1,1], [6,5,0]]
Bob will take the path (1, 1), (1, 2), (2, 2), (3, 2), (3, 3) with profit: 5-4 + 4-2 + 1-4 + 5-2 +0 = 3
In cells (1, 1), (1, 2) Bob will send his dog to cell (1, 3) to get the lanterns.
In the remaining cells he will send the dog to cell (3, 3).
Unfortunately he got lost in an orange grove and wants to reach the exit.
The grove can be represented as a 2D grid consisting of N rows and M columns such that
• The rows are number from 1 to N from top to down.
The columns are numbered from 1 to M from left to right.
Each cell (i, j) of the grid has either of the following
• An orange tree with A[i][j] oranges.
• An infinite number of lanterns.
It is given that cells with lanterns will be have value 0.
the beginning, Bob is at cell (1, 1) and he wants to reach the exit at cell (N, M). He can move either right or down in the grove. As Bob reaches a cell (i, j), he will eat some amount of oranges from the tree in that cell (at most A[i][j]). In case this cell has lanterns, he will not be able to eat any oranges.
Bob wants to mark the path he's following with lanterns, so when he reaches a cell he will send his dog to some cell which has lanterns then the dog will pick up a lantern and comeback to Bob to put the lantern in that cell
The dog can move up, down, left and right in the grid, and the dog travels 1 kilo meter when moving from one cell to another.
When Bob moves from one cell to another, his dog will follow him as well.
Bob defines the profit of a path that leads him to
the exit as the difference between the total amount
of oranges he could eat along that path and theof oranges he could eat along that path and the total distance in kilo meters his dog traveled along that path
Find the maximum profit of a path that leads Bob to the exit of the grove
The distance the dog travels with Bob when Bob moves from cell to another is not included (only the distance of getting lanterns is calculated for the dog)
• Bob will put lanterns in every cell of the path, including the starting and ending cells.
He can also move to a cell which has lanterns, but this will not affect the amount of oranges.
It is guaranteed that there is at least one cell with lanterns.
Input Format
The first line contains an integer, N, denoting the number of rows in Grid.
The next line contains an integer, M, denoting the number of columns in Grid.
Each line i of the N subsequent lines (where 0≤i< N) contains M space separated integers each describing the row Grid[i].
Constraints
1 <= N <= 10^5
1 <= M <= 10^5
0 <= Grid[i][j] <= 10^9
Sample Test Cases
Case 1
Input:
1
1
0
Output:
0
Explanation:
N=1, M-1, Grid=0
Bob is already at the ending cell, bob will not eat oranges and the dog will not travel anywhere since this cell has lanterns.
So the answer is 0.
Output:
2
Explanation:
N-2, M-2, Grid-[[3,0], [5,2]]
In the beginning, Bob will eat 3 oranges at cell (1, 1) then he will send his dog to cell (1, 2) to get a lantern, the dog will travel 2kms back and forth.
Then Bob will move with dog to cell (2, 1), eat 5 oranges and send his dog to cell (1, 2) again, the dog will travel 4kms (2kms for going and 2 for returning).
Finally Bob will move with the dog to the exit cell (2, 2), eat 2 oranges and send his dog to cell (1, 2), the dog will travel 2kms to get the lantern.
The final answer is 3-2 + 5-4 + 2-2 = 2.
Output:
3
Explanation:
N-3, M-3, Grid=[[5,4,0], [1,1,1], [6,5,0]]
Bob will take the path (1, 1), (1, 2), (2, 2), (3, 2), (3, 3) with profit: 5-4 + 4-2 + 1-4 + 5-2 +0 = 3
In cells (1, 1), (1, 2) Bob will send his dog to cell (1, 3) to get the lanterns.
In the remaining cells he will send the dog to cell (3, 3).
👍3
Principal Global hiring Software Engineer
2022 and before batches eligible
Apply Now :
https://careers.principal.com/in/jobs/43329?lang=en-us&iis=Job+Board&iisn=Linkedin
2022 and before batches eligible
Apply Now :
https://careers.principal.com/in/jobs/43329?lang=en-us&iis=Job+Board&iisn=Linkedin
Honeywell hiring Software Engineer l
Entry level
Apply Now :- https://careers.honeywell.com/us/en/job/HONEUSHRD237606EXTERNALENUS/Systems-Engr-I?utm_source=linkedin&utm_medium=phenom-feeds
Entry level
Apply Now :- https://careers.honeywell.com/us/en/job/HONEUSHRD237606EXTERNALENUS/Systems-Engr-I?utm_source=linkedin&utm_medium=phenom-feeds
ALL IT Companies posted active links apply fast
🎯1.IBM https://IBM.contacthr.com/140332758?Codes=SN_LinkedIn
🎯2. Check out this job at Tech Mahindra: https://www.linkedin.com/jobs/view/3986195639
🎯3. JP Morgan https://JPMorganChase.contacthr.com/140898093
🎯4. Amazon https://www.amazon.jobs/jobs/2678286/-graduate-software-dev-engineer-?cmpid=SPLICX0248M&utm_source=linkedin.com&utm_campaign=cxro&utm_medium=social_media&utm_content=job_posting&ss=paid
🎯5. Barclays https://search.jobs.barclays/job/-/-/13015/64995555968?src=JB-12860
🎯6. Honeywell https://careers.honeywell.com/us/en/job/HONEUSHRD237606EXTERNALENUS/Systems-Engr-I?utm_source=linkedin&utm_medium=phenom-feeds
🎯7. Greenhouse https://boards.greenhouse.io/nubank/jobs/2569175?gh_src=3c8e02de1&source=LinkedIn
🎯8. NTT
https://careers.services.global.ntt/global/en/job/NTT1GLOBALR117329EXTERNALENGLOBAL/Software-Applications-Development-Engineer?utm_source=directemployers&utm_medium=phenom-feeds
🎯9. Coforge
https://careers.coforge.com/#!/job-view/technical-analyst-gurugram-2024070222110474?source=linkedin
🎯10.amdocs https://amdocs.eightfold.ai/careers?location=IN&pid=563430998077578&domain=amdocs.com&sort_by=relevance
Telegram:- @allcoding1
Share with your friends 👭👬
🎯1.IBM https://IBM.contacthr.com/140332758?Codes=SN_LinkedIn
🎯2. Check out this job at Tech Mahindra: https://www.linkedin.com/jobs/view/3986195639
🎯3. JP Morgan https://JPMorganChase.contacthr.com/140898093
🎯4. Amazon https://www.amazon.jobs/jobs/2678286/-graduate-software-dev-engineer-?cmpid=SPLICX0248M&utm_source=linkedin.com&utm_campaign=cxro&utm_medium=social_media&utm_content=job_posting&ss=paid
🎯5. Barclays https://search.jobs.barclays/job/-/-/13015/64995555968?src=JB-12860
🎯6. Honeywell https://careers.honeywell.com/us/en/job/HONEUSHRD237606EXTERNALENUS/Systems-Engr-I?utm_source=linkedin&utm_medium=phenom-feeds
🎯7. Greenhouse https://boards.greenhouse.io/nubank/jobs/2569175?gh_src=3c8e02de1&source=LinkedIn
🎯8. NTT
https://careers.services.global.ntt/global/en/job/NTT1GLOBALR117329EXTERNALENGLOBAL/Software-Applications-Development-Engineer?utm_source=directemployers&utm_medium=phenom-feeds
🎯9. Coforge
https://careers.coforge.com/#!/job-view/technical-analyst-gurugram-2024070222110474?source=linkedin
🎯10.amdocs https://amdocs.eightfold.ai/careers?location=IN&pid=563430998077578&domain=amdocs.com&sort_by=relevance
Telegram:- @allcoding1
Share with your friends 👭👬
👍3
🎯 Citrusbug Off Campus Drive 2024 Freshers | Software Engineer | Rs. 4-6 LPA
Job Role : Software Engineer
Qualification : B.Tech /M.Tech / MCA
Experience : Freshers
Package : 4-6 LPA
Apply Now:- https://citrusbug.com/career/software-engineer
Telegram:- @allcoding1
Share with your friends 👭👬
Job Role : Software Engineer
Qualification : B.Tech /M.Tech / MCA
Experience : Freshers
Package : 4-6 LPA
Apply Now:- https://citrusbug.com/career/software-engineer
Telegram:- @allcoding1
Share with your friends 👭👬
🎯Cognizant Hiring Fresher For IT Programmer Trainee
Location: PAN India
Qualification: Any 3 Years Graduate
Work Experience: Fresher
CTC: 2.5 LPA
Last Date: 7th Agust
Apply Now:-
https://app.joinsuperset.com/join/#/signup/student/jobprofiles/92217fe2-2130-461c-9be3-97c0ffb9e9da
Telegram:- @allcoding1
Share with your friends 👭👬
Location: PAN India
Qualification: Any 3 Years Graduate
Work Experience: Fresher
CTC: 2.5 LPA
Last Date: 7th Agust
Apply Now:-
https://app.joinsuperset.com/join/#/signup/student/jobprofiles/92217fe2-2130-461c-9be3-97c0ffb9e9da
Telegram:- @allcoding1
Share with your friends 👭👬
👍2