Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Viewport Layout Window Aggregation

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

Your question is Viewport Layout Window Aggregation. 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

A mobile feed view contains n vertically stacked cards with heights stored in integer array heights, and a viewport of height viewport. During scrolling, rendering all cards is too expensive. Return the smallest contiguous range [start, end] such that the sum of heights[start:end+1] is at least viewport. If multiple ranges have the same length, return the one with the smallest start. If no such range exists, return [-1, -1].

Constraints

  • 1 <= heights.length <= 10^5
  • 1 <= heights[i] <= 10^4
  • 1 <= viewport <= 10^9

Function Signature

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