GC Content
Easy · rating 1000 · Strings, Math
Read a DNA strand (letters A C G T). Print its GC content: the percentage of nucleotides that are G or C, rounded down to a whole percent.
Editorial
GC Content reports the percentage of a DNA strand that is G or C, rounded down — a common bioinformatics measure. Count the G/C bases and scale by 100 over the length with integer division.
gc = sum(1 for c in dna if c in 'GC')
print(100 * gc // len(dna))Complexity
Time: O(n). Space: O(1).
Related problems
- Binary to Decimal — Medium
- Product of Digits — Easy
- RGB to Hex Color — Easy
- Sum of Digits — Easy
- Keystroke Count — Easy
- IP Address to Integer — Medium