FastPrepEmail Chunk Verification

Email Chunk Verification

Google logoGoogle● EasyFULLTIMEOA
Learn

Problem statement

Given a string email, a lookup string verification, and a positive chunk length k, return a verification string.

Split email from left to right into consecutive chunks of at most k characters. For each chunk, sum its character values, take that sum modulo verification.length, and append the character at that index in verification.

Practice interpretation

For this exercise, assume lowercase letters have values a = 0 through z = 25, and :, /, and . have values 26, 27, and 28, respectively. Lookup indices start at zero. Include a final chunk even when it contains fewer than k characters. Reset the sum for each chunk. The input name is only a label; this task does not validate email-address syntax.

Return the selected characters in chunk order. Do not modify either input string.

Function

emailChunkVerification(email: String, verification: String, k: int) → String

Examples

Example 1

email = "abcde"verification = "wxyz"k = 2return = "xxw"

Chunk sums are 1, 5, 4. Their remainders modulo 4 select "xxw".

Example 2

email = "a:/z."verification = "0123456789"k = 2return = "628"

Chunk sums are 26, 52, 28. Their remainders modulo 10 select "628".

Example 3

email = "xyz"verification = "abcdef"k = 8return = "a"

Chunk sums are 72. Their remainders modulo 6 select "a".

Constraints

  • For this exercise, assume 1 <= email.length <= 10^5 and every character in email is a lowercase English letter, :, /, or ..
  • Assume 1 <= verification.length <= 10^4 and verification contains printable ASCII characters.
  • Assume 1 <= k <= 10^5; k may exceed email.length.

More Google problems

See Google hiring insights
public String emailChunkVerification(String email, String verification, int k) {
    // Write your code here
}
email"abcde"
verification"wxyz"
k2
expected"xxw"
Checking account…