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
Linked List: Add Two Numbers
00:00
5 left

Linked List: Add Two Numbers

EasyPython

Problem

Lytx may represent large event-count values as linked lists to avoid fixed-width integer limits. Given two non-negative integers stored in reverse digit order, return their sum in the same linked-list format.

Each node contains one decimal digit. The head node stores the least significant digit. The lists may have different lengths, and the result must not contain unnecessary leading zero nodes, except when the sum is zero.

Formal Specification

Implement add_two_numbers(l1, l2), where l1 and l2 are heads of singly linked lists whose node values are integers from 0 through 9. Return the head of a new singly linked list representing l1 + l2 in reverse digit order. The provided environment defines ListNode with fields val and next.

For test cases, each linked list is written as a JSON array for readability, and the evaluator converts it to a linked list before calling the function. The expected result is written as an array of node values.

Constraints

  • 1 <= len(l1), len(l2) <= 100
  • Each node value is an integer from 0 through 9
  • The input lists represent non-negative integers
  • Input lists may have different lengths

Function Signature

def add_two_numbers(l1, l2):
Interviewer

Your question is Linked List: Add Two Numbers. 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.