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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started

Find a Bug in Code

MediumCoding00:00
Practice interviewer
In session
5 left
00:00

Your question is Find a Bug in Code. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

You need to log in / sign up to chat or submit.

Problem

Two Sigma engineers spend as much time reading quantitative code as writing it. You're reviewing a teammate's function that computes a rolling volume-weighted average price (VWAP) for a trade blotter before it feeds the next backtest run.

def rolling_vwap(trades, window=5, seen_symbols=[]):
    results = []
    for i in range(len(trades)):
        seen_symbols.append(trades[i]["symbol"])
        start = i - window
        chunk = trades[start:i]
        total_value = sum(t["price"] * t["volume"] for t in chunk)
        total_volume = sum(t["volume"] for t in chunk)
        vwap = total_value // total_volume
        results.append(vwap)
    return results, seen_symbols

Find every bug in this function and explain what a backtest run would actually show because of each one, before describing your fix.