This multi-part prompt evaluates core competencies in data structures and algorithms (time-based key-value design, duplicate removal in sorted linked lists), JavaScript language features (currying and value coercion), and frontend asynchronous control flow (timers, Promises/async-await).
You are given several independent coding tasks that appeared across an OA and frontend-focused interviews. Implement each as specified.
Design a data structure that supports storing multiple values for the same key at different timestamps.
set(key: string, value: string, timestamp: int) -> void
get(key: string, timestamp: int) -> string
get ruleReturn the value associated with key at the largest timestamp t such that t <= timestamp. If no such timestamp exists for that key, return an empty string.
O(log n)
per
get
per key.
set
calls.
Given the head of a sorted singly linked list, remove duplicates so that each value appears only once.
head
of a sorted list.
Example: 1 -> 1 -> 2 -> 3 -> 3 becomes 1 -> 2 -> 3.
Implement a JavaScript function add that supports chained calls via currying.
Option A (explicit terminator):
add(1)(2)(3)()
returns
6
.
Option B (implicit coercion):
add(1)(2)(3) == 6
is
true
(via
valueOf
/
toString
).
Handle common edge cases (e.g., add(0), negative numbers).
Implement a function that repeatedly cycles through traffic lights in order:
Requirements:
n
cycles if you choose to add a parameter).
async
/
await
/ timers).
console.log('red')
at the moment the light turns on.