Skip to content

Instantly share code, notes, and snippets.

@vdparikh
Last active September 6, 2023 17:30
Show Gist options
  • Save vdparikh/2256be0fad358227b0c1bc48e853d3a9 to your computer and use it in GitHub Desktop.
Save vdparikh/2256be0fad358227b0c1bc48e853d3a9 to your computer and use it in GitHub Desktop.
Details

The following coding problem requires Senior engineer level or up to finish two questions within 50 minutes.

We are working on a security system for a badged-access room in our company's building.

  1. Given an ordered list of employees who used their badge to enter or exit the room, write a function that returns two collections: a. All employees who didn't use their badge while exiting the room – they recorded an enter without a matching exit. b. All employees who didn't use their badge while entering the room – they recorded an exit without a matching enter.
badge_records = [
  ["Martha",   "exit"],
  ["Paul",     "enter"],
  ["Martha",   "enter"],
  ["Martha",   "exit"],
  ["Jennifer", "enter"],
  ["Paul",     "enter"],
  ["Curtis",   "enter"],
  ["Paul",     "exit"],
  ["Martha",   "enter"],
  ["Martha",   "exit"],
  ["Jennifer", "exit"]
] 

Expected output: ["Paul", "Curtis"], ["Martha"]

  1. We want to find employees who badged into our secured room unusually often. We have an unordered list of names and access times over a single day. Access times are given as three or four-digit numbers using 24-hour time, such as "800" or "2250". Write a function that finds anyone who badged into the room 3 or more times in a 1-hour period, and returns each time that they badged in during that period. (If there are multiple 1- hour periods where this was true, just return the first one.) Notice that "10:00" - "11:00" is considered to be within a one-hour period, while "22:51" - "23:52" is not considered to be within a one-hour period.
badge_records = [
  ["Paul", 1315],
  ["Jennifer", 1910],
  ["John", 830],
  ["Paul", 1355],
  ["John", 835],
  ["Paul", 1405],
  ["Paul", 1630],
  ["John", 855],
  ["John", 915],
  ["John", 930],
  ["Jennifer", 1335],
  ["Jennifer", 730],
  ["John", 1630],
]

Expected output: `{"John": [830, 835, 855, 915, 930], "Paul": [1315, 1355, 1405]}

Time: O(N) , Space: O(N) .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment