Determining Nucleotide Assortments
InterviewTime limit1sMemory limit1024 MB
Given a DNA string and many range queries, output the four nucleotides ordered by count in each range, with ties broken by ATGC order.
- Level
Easy3 of 10
- Topics
- Prefix sum, Sorting, String
- Solved
- No attempts yet
Problem
Genes 'R Us analyzes DNA strands to find anomalies, matches, patterns, or other specific items its customers want. You may recall from high school biology that a DNA molecule consists of two chains wrapped around each other to form the double helix. Each chain is made of four types of nucleotides, distinguished by their nitrogen bases: adenine (A), thymine (T), guanine (G), and cytosine (C).
A recent customer of Genes 'R Us wants to quickly determine which of the four nucleotide types is most prevalent in a given section of DNA, and which are second, third, and fourth most prevalent. A strand may contain tens of thousands of nucleotides, and the customer will ask about many sections of the same strand. Your task is to write an efficient program that answers these queries.
Input
The first line is a string describing a DNA strand. It consists only of the characters A, T, G, and C, and its length satisfies . The next line contains a positive integer (), the number of sections to investigate. The following lines each contain a pair of integers and , the start and end positions of a section, where . The two integers in each pair are separated by a single space.
Output
For each section, output one line containing a permutation of ATGC. The first character is the most prevalent nucleotide in the section, the second character is the second most prevalent, and so on. If nucleotides occur equally often, order them by ATGC: A comes before T, G, and C, and T comes before G and C.