Skip to the code
cf.
+10 XP

#223 Pinned Tabs First

easy

A browser shows pinned tabs at the left of the tab bar. tabs lists the open tabs in their current order, and pinned lists tab names in the order the user pinned them (it may mention tabs that are no longer open).

Write arrangeTabs(tabs, pinned) that returns the tabs with every open pinned tab first, in the order of pinned, followed by all the other tabs in their current order.

Example 1

Input: tabs = ["news","mail","docs","chat"], pinned = ["chat","mail"]
Output: ["chat","mail","news","docs"]

Pinned tabs go first in pinned order; news and docs keep their order.

Example 2

Input: tabs = ["a","b"], pinned = ["z"]
Output: ["a","b"]

z is not open, so nothing moves.

Constraints

  • 0 <= tabs.length, pinned.length <= 10000
  • Names in tabs are distinct; names in pinned are distinct.
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).