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
Weather App Implementation
00:00
5 left

Weather App Implementation

MediumPython

Problem

Code a weather app.

Implement a function that returns the latest forecast for a requested city using a weather API response cache. The function should accept a list of requests, where each request is either a lookup for a city or a refresh event that updates that city’s forecast data. Return the forecast value for each lookup in order.

Function signature

def weather_app(requests):

Input

  • requests: a list of requests, each request is a dict with fields:
    • type: either "lookup" or "refresh"
    • city: a string
    • forecast: an integer, present only for "refresh"

Output

  • Return a list of integers, one per "lookup", representing the current cached forecast for that city, or -1 if the city has not been refreshed yet.

Constraints

  • 1 <= len(requests) <= 10^5
  • City names contain only lowercase English letters
  • Refreshes and lookups may be interleaved in any order

Constraints

  • 1 <= len(requests) <= 10^5
  • Each request has type either "lookup" or "refresh"
  • For refresh requests, forecast is an integer
  • City names contain only lowercase English letters
  • Refresh and lookup requests may appear in any order

Function Signature

def weather_app(requests):
Interviewer

Your question is Weather App Implementation. 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.