Tutte le sfide
Facile 1 risolta 100.0% di accettazione

DNA to RNA Transcription

Build an RNA string by replacing every DNA character with its partner.

Cosa imparerai

  • Translate characters with a lookup table
  • Build a new string from mapped characters
  • Handle every character in a sequence

Problema

Mostra traduzione

Build an RNA string by replacing every DNA character with its partner. Use this complete mapping: A → U, C → G, G → C, T → A. Preserve the original order. No biology knowledge is needed.

Implement dna_to_rna(dna).

Input

dna: The DNA string to transform.

Output

Return the transformed string. Empty input returns an empty string.

Vincoli

0 ≤ DNA length ≤ 100,000. Characters are uppercase A, C, G, or T.

Esempi

Esempio 1
Input:
dna = "ACGT"

Output atteso:
expected = "UGCA"
Input:
std::string dna = "ACGT";

Output atteso:
std::string expected = "UGCA";
Input:
string dna = "ACGT";

Output atteso:
string expected = "UGCA";

Spiegazione

A becomes U, C becomes G, G becomes C, and T becomes A, giving UGCA.

Esempio 2
Input:
dna = ""

Output atteso:
expected = ""
Input:
std::string dna = "";

Output atteso:
std::string expected = "";
Input:
string dna = "";

Output atteso:
string expected = "";

Spiegazione

There are no characters to replace, so the result is empty.

Come affrontarlo

Prova prima da solo, poi apri un suggerimento alla volta.

Suggerimento 1

Each DNA letter maps to exactly one RNA letter, so translate character by character.

Suggerimento 2

Use a direct lookup for the four valid symbols while preserving the original order.

Suggerimento 3

An empty input should return an empty string, and every character is guaranteed to be valid.

Complessità attesa

O(n) time, O(n) extra space

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

La migliore soluzione superata di ogni programmatore. Le più veloci, leggere e meglio valutate stanno in alto.

# Programmatore Linguaggio Tempo Memoria Voto dell'IA Soluzione
1 RCRiccardo Corti Python 870 ms - 5/5 Vedi il codice

Impara dagli altri

Soluzioni della community

Attenzione spoiler: 1 soluzione completa sotto Prova prima a risolverla da solo. Puoi comunque sbirciare il codice degli altri sviluppatori e le revisioni dell'IA. Accedi e risolvi la sfida per partecipare alla discussione.