Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Feature Module Implementation in NowInAndroid

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Feature Module Implementation in NowInAndroid. Start with the requirements on the right.

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.

Problem

Implement a bookmark feature module for a Speechify-style app. The module must support adding a bookmark, removing a bookmark, checking whether a bookmark exists, and listing bookmarks in insertion order.

The key requirement is that the feature logic must be isolated from infrastructure concerns. Model the module with a clean interface and keep the core state and operations in pure Python.

Formal Specification

Implement a function bookmark_module(operations) that processes a list of operations and returns the results for read operations.

Each operation is one of:

  1. ("add", id) adds bookmark id if it does not already exist.
  2. ("remove", id) removes bookmark id if it exists.
  3. ("exists", id) returns True if id is bookmarked, otherwise False.
  4. ("list",) returns the current bookmarks in insertion order as a list.

Bookmark ids are integers. Ignore duplicate adds and missing removes.

Constraints

  • 1 <= len(operations) <= 10^5
  • -10^9 <= id <= 10^9
  • Each operation is one of: add, remove, exists, list
  • Duplicate adds must not change state
  • Removing a missing bookmark must do nothing

Function Signature

def bookmark_module(operations):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output