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
Start free
Difference Between Array and Slice in Go
00:00
5 left

Difference Between Array and Slice in Go

HardPython

Problem

What is the difference between an array and a slice in Go?

Asked in the Golang deep-dive interview stage. Implement a simulator that exposes the difference through mutation and append behavior.

Contract

model_go_array_slice(initial, operations) receives an integer list and operations. The initial slice has length and capacity equal to len(initial), and initially shares storage with the array. Return one snapshot for every snapshot operation, each containing the current array and slice lists.

Operations are dictionaries: {"op": "set_array"|"set_slice", "index": i, "value": v}, {"op": "append", "value": v}, or {"op": "snapshot"}.

Constraints

  • 1 <= len(initial) <= 1000
  • 1 <= len(operations) <= 2000
  • All set_array indices are valid for the initial array
  • All set_slice indices are valid for the current slice
  • Operation values are integers
  • At least one snapshot operation is present

Function Signature

def model_go_array_slice(initial, operations):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.