Skip to the code
cf.
+10 XP

#106 Drop Muted Users

easy

A chat app keeps the ids of everyone in a room in userIds. When someone is muted, every copy of their id must be removed before the list is rendered.

Write dropMuted(userIds, muted) that removes every item equal to muted from userIds in place, keeping the other ids in their original order, and shortens the array so it holds only the kept ids. Don't create a second array. The tests check userIds after your function runs.

Example 1

Input: userIds = [4,7,2,7,9], muted = 7
Output: [4,2,9]

Both copies of 7 are removed; 4, 2, 9 keep their order.

Example 2

Input: userIds = [1,2,3], muted = 5
Output: [1,2,3]

Nobody in the room is muted.

Constraints

  • 0 <= userIds.length <= 100000
  • 0 <= userIds[i], muted <= 10^6
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).