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
Fibonacci and Longest Subsequence
00:00
5 left

Fibonacci and Longest Subsequence

MediumPython

Problem

WebMD uses ordered relevance signals to rank content returned by products such as the WebMD Symptom Checker. Implement a function that performs two independent computations: return the nth Fibonacci number and the length of the longest strictly increasing subsequence in an integer sequence.

Use the Fibonacci definition F(0) = 0, F(1) = 1, and F(n) = F(n - 1) + F(n - 2). A subsequence may skip elements, but it must preserve their original order. It is strictly increasing, so equal adjacent values are not allowed.

Formal Specification

Given an integer n and a list of integers nums, return a two-element list [fib, lis_length], where fib is F(n) and lis_length is the length of the longest strictly increasing subsequence of nums.

Constraints

  • 0 <= n <= 100000
  • 0 <= len(nums) <= 100000
  • -10^9 <= nums[i] <= 10^9
  • The subsequence must be strictly increasing

Function Signature

def fibonacci_and_lis(n, nums):
Interviewer

Your question is Fibonacci and Longest Subsequence. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.