Skip to the code
cf.
+10 XP

#571 Serve Image Variants to Screens

easy

A responsive image service has a set of pre-rendered images with widths images. Each waiting screen has a minimum width it needs, in screens. A screen is served if it gets an image at least as wide as it needs. Each image can be sent to only one screen, and each screen gets at most one image.

Write screensServed(screens, images) that returns the largest number of screens that can be served.

Example 1

Input: screens = [320,768,1024], images = [400,300]
Output: 1

Only the 320 screen can be served (with the 400 image). The 300 image is too small for everyone.

Example 2

Input: screens = [320,640], images = [640,1280,320]
Output: 2

Both screens get a wide enough image.

Constraints

  • 0 <= screens.length, images.length <= 30000
  • 1 <= screens[i], images[j] <= 10^4
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).