Codility: GenomicRangeQuery Solution
Lesson 5 Prefix Sums1function solution(S, P, Q) {2 const subtract = (y, x) => ({3 A: y.A - x.A,4 C: y.C - x.C,5 G: y.G - x.G,6 T: y.T - x.T,7 })8 const lowerBound = { A: 0, C: 0, G: 0, T: 0 }9 const accumulatedNucleotideOccurence = { ...lowerBound }10 const nucleotideOccurences = S.split("").map(c => {11 accumulatedNucleotideOccurence[c]++12 return { ...accumulatedNucleotideOccurence }13 })14 const res = P.map((p, i) =>15 subtract(16 nucleotideOccurences[Q[i]],17 p === 0 ? lowerBound : nucleotideOccurences[p - 1]18 )19 ).map(nuOc => (nuOc.A ? 1 : nuOc.C ? 2 : nuOc.G ? 3 : 4))2021 return res22}
Comments
Loading comments...
Tags
codility
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.
Next Post
Codility: CountDiv
Lesson 5 Prefix Sums
Previous Post
Codility: MinAvgTwoSlice
Lesson 5 Prefix Sums