Feature #11: Ad Serving

Implement the "Ad Serving" feature for our "Amazon" project.

Description

A legacy ad service at the Amazon backend creates a list of ads that match a user’s profile and preferences. We have an ad-serving API, read4(), which a client can call to retrieve the next 4 ads in the list.

The legacy API was developed when users were still working on PCs with monitors that had relatively smaller screen sizes and lower resolutions. Showing any more or fewer than four ads wasn’t practical. However, now, many of our users are visiting websites through mobile devices with very small screens or PCs with much larger displays. As a result, sometimes, we also need to serve more than or fewer than four ads at a time.

The client determines the number of ads that can be displayed on a certain client’s screen. This may be more or less than four. Without modifying the backend, we want to implement a read(n) function that will return the next N ads (or fewer, if we reach the end of the ads list).

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.