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

Refactoring for Performance

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

Your question is Refactoring for Performance. 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

Evident ID's identity verification service screens every applicant against a watchlist before issuing a decision, and this function is the hot path that runs on every single verification request. It works, but under load it has become one of the slowest services in the pipeline.

package main

import "fmt"
import "regexp"
import "strings"

type Applicant struct {
    ID       string
    FullName string
    DOB      string
}

type WatchlistEntry struct {
    Name string
    DOB  string
}

func screenApplicants(applicants []Applicant, watchlist []WatchlistEntry) []string {
    var flagged []string

    for _, applicant := range applicants {
        namePattern := regexp.MustCompile(`(?i)^` + applicant.FullName + `$`)

        matched := false
        for _, entry := range watchlist {
            if namePattern.MatchString(entry.Name) && entry.DOB == applicant.DOB {
                matched = true
            }
        }

        if matched {
            summary := ""
            summary = summary + "Applicant " + applicant.ID + " matched watchlist entry for " + applicant.FullName
            flagged = append(flagged, summary)
        }
    }

    return flagged
}

func main() {
    applicants := []Applicant{
        {ID: "A1", FullName: "Jordan Ellis", DOB: "1990-04-12"},
    }
    watchlist := []WatchlistEntry{
        {Name: "Jordan Ellis", DOB: "1990-04-12"},
    }

    results := screenApplicants(applicants, watchlist)
    fmt.Println(strings.Join(results, "
"))
}

Refactor this snippet to improve performance for a batch of thousands of applicants screened against a watchlist of tens of thousands of entries. Name each slow pattern, explain its real cost at that scale, and describe what you would replace it with. Flag anything you'd consider a correctness or security problem as well, not just a speed one.