Skip to content

Commit 294fdb4

Browse files
committed
task: #3475
1 parent 7aaed02 commit 294fdb4

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ Useful for preparing for technical interviews and improving your SQL skills.
173173
- [1341. Movie Rating](./leetcode/medium/1341.%20Movie%20Rating.sql)
174174
- [1907. Count Salary Categories](./leetcode/medium/1907.%20Count%20Salary%20Categories.sql)
175175
- [1934. Confirmation Rate](./leetcode/medium/1934.%20Confirmation%20Rate.sql)
176+
- [3475. DNA Pattern Recognition](./leetcode/medium/3475.%20DNA%20Pattern%20Recognition.sql)
176177
3. [Hard](./leetcode/hard/)
177178
- [185. Department Top Three Salaries](./leetcode/hard/185.%20Department%20Top%20Three%20Salaries.sql)
178179

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Question 3475. DNA Pattern Recognition
3+
Link: https://leetcode.com/problems/dna-pattern-recognition/description/?envType=problem-list-v2&envId=database
4+
5+
Table: Samples
6+
7+
+----------------+---------+
8+
| Column Name | Type |
9+
+----------------+---------+
10+
| sample_id | int |
11+
| dna_sequence | varchar |
12+
| species | varchar |
13+
+----------------+---------+
14+
sample_id is the unique key for this table.
15+
Each row contains a DNA sequence represented as a string of characters (A, T, G, C) and the species it was collected from.
16+
Biologists are studying basic patterns in DNA sequences. Write a solution to identify sample_id with the following patterns:
17+
18+
Sequences that start with ATG (a common start codon)
19+
Sequences that end with either TAA, TAG, or TGA (stop codons)
20+
Sequences containing the motif ATAT (a simple repeated pattern)
21+
Sequences that have at least 3 consecutive G (like GGG or GGGG)
22+
Return the result table ordered by sample_id in ascending order.
23+
*/
24+
25+
SELECT
26+
sample_id,
27+
dna_sequence,
28+
species,
29+
(CASE
30+
WHEN LEFT(dna_sequence, 3) = 'ATG'
31+
THEN 1
32+
ELSE 0
33+
END) AS has_start,
34+
(CASE
35+
WHEN RIGHT(dna_sequence, 3) IN ('TAA', 'TAG', 'TGA')
36+
THEN 1
37+
ELSE 0
38+
END) AS has_stop,
39+
(CASE
40+
WHEN dna_sequence ~ 'ATAT'
41+
THEN 1
42+
ELSE 0
43+
END) AS has_atat,
44+
(CASE
45+
WHEN dna_sequence ~ 'GGG'
46+
THEN 1
47+
ELSE 0
48+
END) AS has_ggg
49+
FROM Samples
50+
ORDER BY sample_id ASC

0 commit comments

Comments
 (0)