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
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
Searchable Navigation List State
00:00
5 left

Searchable Navigation List State

MediumPython

Problem

Given a list of reading items, each item has an integer id, a string title, a string author, and a boolean isSaved. Implement a function that supports a small app flow: filter items by a case-insensitive search query on title or author, optionally keep only saved items, sort the visible results by title, and return both the visible list and the currently selected item if its id is still visible. If the selected item is no longer visible after filtering, return null for the selection.

Constraints

  • 1 <= len(items) <= 10^4
  • 0 <= len(title), len(author), len(query) <= 100
  • id values are unique integers
  • Matching must be case-insensitive
  • Visible items must be sorted by title

Function Signature

def filter_navigation_state(items, query, saved_only, selected_id):
Interviewer

Your question is Searchable Navigation List State. 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.