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

Linked List Odd Numbers

EasyPython

Problem

Agoda processes some itinerary data as a singly linked list. Given the head of the list, return a list containing every odd-valued node, preserving the order in which the nodes appear.

Traverse the linked list once. Do not modify or reorder the linked list. If the list is empty or contains no odd values, return an empty list.

Formal Specification

The input is head, either None or a reference to a singly linked-list node with two fields:

  • val: an integer
  • next: a reference to the next node or None

Return a standard list of integers containing exactly the values for which value % 2 != 0.

For the examples and test cases, an input array such as [4, 7, 2] represents the linked list 4 -> 7 -> 2. The evaluation harness constructs the linked-list nodes before calling the function.

Constraints

  • 0 <= n <= 10^4, where n is the number of nodes
  • -10^9 <= node.val <= 10^9
  • The list contains no cycles
  • The input linked list must not be modified

Function Signature

def get_odd_values(head):
Interviewer

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

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.