Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.