Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
De Bruijn Graph in Python
00:00
5 left

De Bruijn Graph in Python

MediumPython

Problem

A simplified sequence-assembly utility for 10x Genomics Cell Ranger needs to represent overlaps between adjacent DNA k-mers. Given a DNA sequence and an integer k, construct its directed de Bruijn graph.

Formal Specification

Implement de_bruijn_graph(sequence, k). The input sequence is a non-empty string containing uppercase DNA bases, and k is an integer. For every substring of length k, create a directed edge from its first k - 1 characters to its last k - 1 characters. Return a dictionary mapping each node to a list of destination nodes.

Include nodes that appear only as destinations. Preserve duplicate edges because repeated k-mers represent repeated observations. Store each node's outgoing destinations in the order their corresponding k-mers occur from left to right in the sequence. Python dictionary insertion order determines the output order of keys.

Constraints

  • 1 <= len(sequence) <= 10^5
  • 2 <= k <= len(sequence)
  • sequence contains only uppercase DNA bases: A, C, G, and T
  • Repeated k-mers must produce repeated edges
  • Adjacency lists must preserve left-to-right occurrence order

Function Signature

def de_bruijn_graph(sequence, k):
Interviewer

Your question is De Bruijn Graph in Python. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.