Facebook Pixel

Amazon Online Assessment 2021 (OA) - Recent Items

A company aims to enhance how the 'Recently Viewed Items' page operates; they're introducing novel features to make it more user-friendly. One of the key changes is to rearrange the positioning of items based on their usage; if a previously viewed item is accessed again, it will be shifted to the foremost position but without disturbing the order of the rest. In the case of first-time viewings, the novel item will be directly added to the prime position.

They are starting with an unpopulated 'Recently Viewed Items' page and adopting a systematic approach. When given a list of accessed items, their aim is to show, from prime to least, the final order of items on the page.

Relevant Amazon OA Problems:

Input

  • logs: the items viewed, in chronological order

Output

the final list of items in the Recently Viewed Items page

Examples

Example 1:

Input:

logs = ['Echo Show 8', 'Kindle Oasis', 'Fire TV Stick', 'Echo Show 8']

Output: ['Echo Show 8', 'Fire TV Stick', 'Kindle Oasis']

Explanation:

Constraints

  • 1<=n<=10^5
  • The length of an item's name does not exceed 10.
  • Item names are alphanumeric.

Try it yourself

Solution

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro