Question: write the code for the given question in c + + , Jujutsu High has 3 freshmen, Yuji Itadori, Magumi Fusigoro, and Nobara Kugisaki. They
write the code for the given question in cJujutsu High has freshmen, Yuji Itadori, Magumi Fusigoro, and Nobara
Kugisaki. They are assigned a list of tasks they must finish together. Each task has
a unique ID However, each has a weird way of choosing their task from the remaining
tasks in the list.
Yuji Itadori: Always chooses the tasks with the max or min ID Min or Max is
decided randomly by him assume probability for each min or max
Megumi Fusigoro: He will choose a k and call the kth smallest ID Kth ID when
all IDs are arranged in ascending order K is chosen randomly from the total tasks
available in the list K Total tasks
Nobara Kugisaki: He will always choose the median ID If there are n tasks in
the list, the median will be defined as n take floor valueth ID when all of
them are arranged in ascending order. For both odd and even n
Page
Sataru Gojo wants to digitize this process of choosing tasks and is asking for your
suggestions on the data structure that would be ideal for this scenario. Your task is to
design a data structure that supports the query of each of the three freshmen. The data
structure should be highly efficient. It should return the task ID in Ologn for all
scenarios.
Note: Once the task is assigned to someone, it cant be reassigned to someone else. It
must be deleted from your data structure. Taking the input, setting list can take On
but query execution should be in Ologn
Input example: a list of unique task IDs and query or
Return the task ID for the corresponding candidate.
Input Query:
Output: Max element, is no longer available in the list after query
Input Query:
Enter k:
Output: rd smallest in the list.
Input Query:
Output: Initial length was n; after removing elements, the new length is n
median So the nd smallest element is
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
