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:
- Recent Items
- Max Subjects Number
- Find Password Strength
- Economy Mart
- Pth Factor
- Unique Character
- Common Prefix
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.