TutorMe homepage
Subjects
PRICING
COURSES
Start Free Trial
Shri H.
Works at Samsung
Tutor Satisfaction Guarantee
Basic Math
TutorMe
Question:

If n is an integer that leaves a remainder of 4 upon division by 6, what is the remainder of n upon division by 3?

Shri H.

Solution: Note that this example is similar to the above problem, but with a larger remainder. Now, since n leaves a remainder of 4 upon division by 6, we have n=6k+4 where 6k is the largest multiple of 6 that goes into n. This can also be written as n =3(2k)+4 =3(2k+1)+1 In comparison to the example above, now 3(2k+1) is the largest multiple of 3 that goes into n . This shows that the remainder of upon division by 3 is 1.

C Programming
TutorMe
Question:

Given a sequence, Write a C Program to find the length of the longest palindromic subsequence in it. For example if the given sequence is “BBABCBCAB”, then the output should be 7 as “BABCBAB” is the longest palindromic subseuqnce in it. “BBBBB” and “BBCBB” are also palindromic subsequences of the given sequence, but not the longest ones.

Shri H.

###PSEUDO-CODE### Let X[0..n-1] be the input sequence of length n and L(0, n-1) be the length of the longest palindromic subsequence of X[0..n-1]. If last and first characters of X are same, then L(0, n-1) = L(1, n-2) + 2. Else L(0, n-1) = MAX (L(1, n-1), L(0, n-2)). // Everay single character is a palindrom of length 1 L(i, i) = 1 for all indexes i in given sequence // IF first and last characters are not same If (X[i] != X[j]) L(i, j) = max{L(i + 1, j),L(i, j - 1)} // If there are only 2 characters and both are same Else if (j == i + 1) L(i, j) = 2 // If there are more than two characters, and first and last // characters are same Else L(i, j) = L(i + 1, j - 1) + 2 ###CODE### #include<stdio.h> #include<string.h> // A utility function to get max of two integers int max (int x, int y) { return (x > y)? x : y; } // Returns the length of the longest palindromic subsequence in seq int lps(char *str) { int n = strlen(str); int i, j, cl; int L[n][n]; // Create a table to store results of subproblems // Strings of length 1 are palindrome of lentgh 1 for (i = 0; i < n; i++) L[i][i] = 1; // Build the table. Note that the lower diagonal values of table are // useless and not filled in the process. The values are filled in a // manner similar to Matrix Chain Multiplication DP solution (See // https://www.geeksforgeeks.org/archives/15553). cl is length of // substring for (cl=2; cl<=n; cl++) { for (i=0; i<n-cl+1; i++) { j = i+cl-1; if (str[i] == str[j] && cl == 2) L[i][j] = 2; else if (str[i] == str[j]) L[i][j] = L[i+1][j-1] + 2; else L[i][j] = max(L[i][j-1], L[i+1][j]); } } return L[0][n-1]; } /* Driver program to test above functions */ int main() { char seq[] = "GEEKS FOR GEEKS"; int n = strlen(seq); printf ("The lnegth of the LPS is %d", lps(seq)); getchar(); return 0; }

Algebra
TutorMe
Question:

What is the sum of all possible solutions for x of the equation x ( x - k ) = k + 1? (A) 0 (B) 1 (C) k (D) k + 1 (E) 2k - 1

Shri H.

Let k=2. x(x-2) = 2+1 x^2 - 2x = 3 x^2 - 2x - 3 = 0. (x-3)(x+1) = 0 x = 3, -1 Sum = 3+(-1) = 2. This is our target. Now we plug k=2 into all the answer choices in order to see which yields our target of 2. Only answer choice C works.

Send a message explaining your
needs and Shri will reply soon.
Contact Shri