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
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

API Code Efficiency Review

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

Your question is API Code Efficiency Review. 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

Paycom's payroll API exposes an endpoint that calculates a pay period's gross pay for every employee on a client's account, factoring in overtime and per-employee deduction plans, before the numbers are shown to a payroll admin for approval.

package payroll

import "fmt"

type Employee struct {
	ID           string
	HourlyRate   float64
	HoursWorked  float64
	DeductionIDs []string
}

func CalculateGrossPay(employees []Employee, db *Database) map[string]float64 {
	results := map[string]float64{}

	for _, emp := range employees {
		var deductionTotal float64
		for _, id := range emp.DeductionIDs {
			deduction := db.GetDeduction(id)
			deductionTotal += deduction.Amount
		}

		var pay float64
		if emp.HoursWorked > 40 {
			regularHours := 40.0
			overtimeHours := emp.HoursWorked - 40
			pay = regularHours*emp.HourlyRate + overtimeHours*emp.HourlyRate
		} else {
			pay = emp.HoursWorked * emp.HourlyRate
		}

		pay = pay - deductionTotal
		results[emp.ID] = pay
		fmt.Println("calculated pay for", emp.ID)
	}

	return results
}

Explain what this function is doing, then identify what makes it slow and incorrect at scale, and how you would make it both faster and correct for a client with thousands of employees.