The Google online challenge 2020 for university undergraduates 2021 batch was held on August 22, 2020. Before this round, some shortlisting was done based on your resume.
The test was conducted on HackerEarth platform. The test consisted of two coding questions and the time allotted was 60 minutes. My set of questions are mentioned below.
- First Question: You are given a string S ( having lowercase English letters only). In one operation, you can remove the substring “pr” from the string S and get amount X or you can remove the substring “rp” and get the amount Y.
Find the maximum amount you can get if you perform zero or more such operations optimally.
- Substring of a string S is defined as a continuous sequence of characters in S.
- After removing “pr” or “rp”, the order of remaining letters should remain the same.
abppprrr (string S) 5 4 (value of X and Y )
X= 5, Y=4.
Remove substrings are mentioned :
Remove “pr”, new string S=”abpprr”.
Remove “pr”, new string S=”abpr”.
Remove “pr”, new string S=” “.
In total, we removed pr 3 times, so total score is 3*X + 0*Y = 3*5 =15.
- Second Question: Given an array A of N integers and another array B of M integers (not necessarily distinct). The task is to find the minimum number of elements to be added in B so that A becomes subsequence of B. Note that you can add elements at any position in B.
A subsequence is a sequence that can be derived by deleting some or no elements from the sequence without changing the order of remaining elements.
5 6 ( size of A array and B array) 1 2 3 4 5 ( A array ) 2 5 6 4 9 12 ( B array )
Explanation: We need to add 3 numbers in B such that A will become subsequence of B.
We added 1 at the start of B and elements 3, 4 between 2 and 5. Now array B becomes [1, 2, 3, 4, 5, 6, 4, 9, 12] and A is a subsequence of B.