Oracle interview implement a specific priority queue in python

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2021-07-20Added By Anonymous
Source: Link

Company: Oracle
Role: unknown
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

I got an interview from Oracle. I would like to share the question. The below is all the info of the question. Can anyone post your coding solution?
I did not finish all the functions by the time. Hope someone can show the code, so I can learn.Thanks

Can you implement a special priority queue class using python list with the following properties
and methods: (your should use ascending priority)
- Items in the queue can be flagged as fixed.
- Fixed items cannot be removed from the queue, and should stay in the queue
permanently
- Provide the following methods:
1. insert(item, permanent=False):
-add item into the queue in the proper position based on the priority
and flag the item to permanent if permanent==True
-if the queue is full, the new item replaces a non-permanent item with
the least priority
2. sample_items(n)
-select n items based on priority(n highest priority items), return a list
of selected items
-remove selected items from the queue if they are not flagged as
permanent
3. checkfull()
- should return True if the queue is full

Comments