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

Add Method for Functional Requirement

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

Your question is Add Method for Functional Requirement. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

You need to log in / sign up to chat or submit.

Problem

AVIV Group runs real-estate listing portals, and this service tracks a listing's price history. Product wants a way to surface listings whose price dropped meaningfully in the last few days, for a "price drop" feed.

interface PriceEntry {
  price: number;
  recordedAt: Date;
}

interface Listing {
  id: string;
  address: string;
  priceHistory: PriceEntry[];
  active: boolean;
}

class ListingService {
  private listings: Listing[] = [];

  addListing(listing: Listing): void {
    this.listings.push(listing);
  }

  recordPriceChange(listingId: string, newPrice: number, recordedAt: Date): void {
    const listing = this.listings.find(l => l.id === listingId);
    if (!listing) return;
    listing.priceHistory.push({ price: newPrice, recordedAt });
  }

  getActiveListings(): Listing[] {
    return this.listings.filter(l => l.active);
  }
}

Add a method getListingsWithPriceDrop(thresholdPercent, withinDays) that returns active listings whose price dropped by at least thresholdPercent percent within the last withinDays days, comparing the earliest and latest price recorded in that window. Explain your implementation in writing: how you compute the window, how you compare prices, and every edge case you handle, including a listing with only one price point in the window, unsorted priceHistory, an inactive listing, and no drop at all.