TIP103 Unit 3 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
attendees where each element represents the priority level of an attendee, and an integer priority that indicates a particular level of priority.attendees list rearranged such that attendees with lower priority appear first, followed by those with the exact priority, and finally those with higher priority, while preserving the relative order within each group.Plan the solution with appropriate visualizations and pseudocode.
General Idea: Use a three-way partitioning approach similar to the Dutch National Flag problem to rearrange the attendees list according to the specified priority while maintaining the relative order within each group.
1. Initialize three empty lists:
* `less` to collect attendees with priority less than the specified priority.
* `equal` to collect attendees with priority equal to the specified priority.
* `greater` to collect attendees with priority greater than the specified priority.
2. Iterate through each attendee in `attendees`:
1. If the current attendee's priority is less than the specified priority:
* Append it to `less`.
2. If the current attendee's priority is greater than the specified priority:
* Append it to `greater`.
3. If the current attendee's priority is equal to the specified priority:
* Append it to `equal`.
3. Concatenate `less`, `equal`, and `greater` in order.
4. Return the concatenated result.
⚠️ Common Mistakes
def arrange_attendees_by_priority(attendees, priority):
less = []
equal = []
greater = []
for attendee in attendees:
if attendee < priority:
less.append(attendee)
elif attendee == priority:
equal.append(attendee)
else:
greater.append(attendee)
return less + equal + greater
