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
Grid Wind Simulation Function
00:00
5 left

Grid Wind Simulation Function

MediumPython

Problem

Write a function that takes the grid and the wind string as input, and returns the total numbers of leaves remaining on the grid after all wind events have occurred. Example: Input: Grid: [[1, 0, 2], [4, 1, 0], [0, 3, 1]], Wind: “RR” Output: 4

Asked in the online_assessment stage. One of the CoderPad OA problems, candidate passed correctness tests but not fully optimized within the time limit.

For grading, each wind character removes one outermost column. R removes the rightmost remaining column and L removes the leftmost remaining column. If consecutive wind characters are identical, the removal side alternates, so RR removes the rightmost column and then the leftmost column. Return the sum of all values in columns that remain. The grid is rectangular, and an event after all columns have been removed has no effect.

Constraints

  • 0 <= number of rows <= 10^4
  • 0 <= number of columns <= 10^4
  • The grid is rectangular
  • 0 <= grid[row][column] <= 10^6
  • 0 <= len(wind) <= 10^5
  • Each character in wind is either L or R

Function Signature

def remaining_leaves(grid, wind):
Interviewer

Your question is Grid Wind Simulation Function. 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.