Google Internship 2020 – Google Online Challenge(1st Coding Round)
Recently I Got An E-mail From Google That I’ve been selected from the Resume review round To Google’s Online Challenge round. On the 29th Of August, I’ve given That Challenge and face these two problems, which I want to share with all…
A Special String: You Are given a string S consisting of the lowercase Latin alphabet, a – z. Find the minimum number of characters that must be changed to make S special.
A string S is said to be special if and only if for all (S[i], S[j]) where (1 ≤ i ≤ N/2) and (N/2 + 1 ≤ j ≤ N) one of the following condition is true:
S[i] > S[j] S[i] < S[j] S[i] = S[j] S[i]: Represents the ith character of string S(1-based indexing)
- The first line contains an integer T denoting the number of test cases
- The first line of each case contains an integer N denoting the length of S
- The second line of each test case contains a string S
Output format: Print an integer denoting the minimum number of changes required for each test case in a new line.
1 ≤ T ≤ 5 1 ≤ N ≤ 103 N is Even
1 6 aababc
Change S = ‘d’(1 – based indexing) Change S = ‘d’ New String = ‘aabddc’ Now all Pairs (S[i],S[j]) Satisfy the second condition, S[i] < S[j].
A Special Matrix: You are given an N × N matrix A. The matrix consists of positive integers. In one move, you can apply the following single transformation to the matrix:
Select an arbitrary element of the matrix and increase or decrease it by 1. Each element can be increased or decreased for any arbitrary number of times.
A special number P is a non-negative integer for which the following quadratic equation has at least one negative integer root:
X2 - 2 × P + x = 0
A matrix is called special if at least one of the following conditions is true:
- The matrix has a row with special numbers only.
- The matrix has a column with special numbers only.
Your task is to count the minimum number of moves required to get special matrix A
- The first line contains T denoting the number of test cases.
- The first line of each test case contains an integer N denoting the number of rows and columns.
- Next N lines of each test case contain N integers denoting the initial matrix A.
For each test case, print a single integer in a new line denoting the minimum number of moves required to get a special matrix from the provided matrix. if you have already obtained a special matrix, then print 0.
1 ≤ T ≤ 10 1 ≤ N ≤ 500 1 ≤ A[i][j] ≤ 1011(1 ≤ i ≤ N, 1 ≤ j ≤ N)
1 3 1 2 3 4 5 6 7 8 9
Explanation: Either the first row or third column can be modified to convert the matrix into a special matrix with a minimum number of moves. The first row can be transformed into [1,3,3] by increasing one time the second element of the first row.
Please Login to comment...