The Genomic Bottleneck

Difficulty: MEDIUMID: redos-genetics-gemini

The Scenario

You are building a Genetics RAG Pipeline that retrieves metadata & research papers based on DNA sequences using the Gemini API. To save money on tokens, you run a local Python "Guardrail" to validate input sequences before sending them to the LLM.

The Incident

A researcher pasted a malformed gene sequence into the dashboard. Suddenly, your backend froze. No errors, no crash logs—just 100% CPU usage. Your Gemini API quota is sitting unused, but your local container is completely unresponsive.

The Stakes

  • The Victim: Your ingestion service.
  • The Culprit: A regex validator intended to check for "Poly-A Tails" (sequences of Adenine).
  • The Result: A "ReDoS" (Regular Expression Denial of Service) that forces your CPU to check millions of paths for a single string.

The Goal

Patch the validate_poly_a_tail function.

  • The current logic uses ^((A+)+)+$ which has O(2^n) complexity.
  • Your Task: Rewrite the regex to accept valid Poly-A tails instantly (under 10ms) without hanging on malformed inputs.
solution.py
Loading...
SYSTEM_LOGS
// Waiting for execution trigger...