Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Filtering Arrays by User Roles
00:00
5 left

Filtering Arrays by User Roles

EasyPython

Problem

Altium 365 workspace administration may need to display only users with selected roles, such as Designer or Administrator. Implement a function that returns a new array containing only users whose role appears in the allowed roles list.

The result must preserve the original user order, include each matching user at most once, and leave the input arrays unchanged. Role matching is case-sensitive and requires an exact string match.

Formal Specification

Implement filter_workspace_users(users, allowed_roles).

  • users is an array of objects. Each object contains a string name and a string role.
  • allowed_roles is an array of role strings. It may contain duplicate values.
  • Return a new array of user objects whose role is included in allowed_roles.
  • Do not modify users or allowed_roles.

Use a data structure that keeps role membership checks efficient when the input is large.

Constraints

  • 0 <= len(users) <= 100,000
  • 0 <= len(allowed_roles) <= 100,000
  • Each user contains string fields named "name" and "role"
  • Role comparisons are exact and case-sensitive

Function Signature

def filter_workspace_users(users, allowed_roles):
Interviewer

Your question is Filtering Arrays by User Roles. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.