Problem · String

Get Sequence

Learn this problem
MediumAmazon logoAmazonNEW GRADOA
See Amazon hiring insights

Problem statement

Data scientists at Amazon are working on a utility for genome sequencing algorithms. The utility finds anagram patterns in a pair of DNA sequence strings. A pair of DNA is special if they are anagrams after removing any number of occurrences of at most one character from each DNA sequence.

Given n pairs of DNA, for each pair, attempt to make them anagrams. Return a list of boolean values, one for each pair, where True means a pair is special.

Complete the function getSequence in the editor below.

getSequence has the following parameter(s):

  1. String dna[n][2]: the pairs of DNA sequences.

The function returns boolean[n]: true if the pair is special, and false otherwise.

Function

getSequence(dna: String[][]) → boolean[]

Examples

Example 1

dna = [["safddadfs", "famafmss"]]return = [true]

The strings are anagrams after removing all the occurrences of character 'd' from s and character 'm' from t. Return [True].

Note: It is not required that all instances of a character be removed. For example, given 'aab' and 'ba', one 'a' can be removed from 'aab' to leave 'ab'.

Example 2

dna = [["abcee", "acdeedb"], ["sljffsaje", "sljsje"]]return = [true, false]

For pair 1, remove 'd' from the second string and leave the first string untouched.

For pair 2, dna1 contains 'f' and 'a' which are not in dna2. They cannot be anagrams after removing only one character from dna1.

Example 3

dna = [["abcdee", "abcde"]]return = [true]

Remove one occurrence of 'e' from dna1.

Constraints

  • 1 <= n <= 10
  • 1 <= length of dna[i][0], dna[i][1] <= 10000
  • The strings in dna[i][0] and dna[i][1] consist of lowercase English letters only.

More Amazon problems

drafts saved locally
public boolean[] getSequence(String[][] dna) {
  // write your code here
}
dna[["safddadfs", "famafmss"]]
expected[true]
checking account