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
Odd Numbers With Recursion
00:00
5 left

Odd Numbers With Recursion

EasyPython

Problem

In an Incedo analytics utility, generate a sequence of odd numbers for an inclusive integer range. Write a recursive function that returns all odd integers from start through end in ascending order. The caller may print the returned values.

Your solution must use recursion and must not use for or while loops. Handle ranges where start is even or odd. If start is greater than end, return an empty list.

Formal Specification

Implement odd_numbers(start, end):

  • Input: Two integers, start and end.
  • Output: A list containing every odd integer x such that start <= x <= end, ordered from smallest to largest.
  • The function must make progress toward the base case on every recursive call.

Constraints

  • -10^4 <= start <= 10^4
  • -10^4 <= end <= 10^4
  • The range contains at most 2 * 10^4 + 1 integers
  • Use recursion and no for or while loops

Function Signature

def odd_numbers(start, end):
Interviewer

Your question is Odd Numbers With Recursion. 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.