You are given several small coding tasks. Implement each as described.
Task A — Convert snake_case to camelCase
Write a function that converts an identifier from snake_case to camelCase.
-
Input: a string
s
containing lowercase letters
a-z
and underscores
_
.
-
Output: the camelCase version.
-
Rules/edge cases:
-
Consecutive underscores should be treated as a single word separator (ignore empty parts).
-
If
s
starts/ends with underscores, ignore those underscores.
-
The first word remains lowercase; each subsequent word is capitalized.
Example:
-
"hello_world" -> "helloWorld"
-
"__my__var__name_" -> "myVarName"
Task B — Format an integer with thousands separators
Write a function that formats a (possibly negative) integer with commas as thousands separators.
-
Input: an integer
n
(may be large; assume it fits in 64-bit signed integer).
-
Output: a string representation using commas every 3 digits from the right.
Examples:
-
123 -> "123"
-
1234 -> "1,234"
-
-12345678 -> "-12,345,678"
Task C — Validate an OCR string under 180° rotation
An OCR system outputs a string t that may contain digits and a few letters. You need to decide whether it can represent an integer between 1 and 200 inclusive under either normal reading or after a 180-degree rotation.
Define a rotation mapping rot(c) for characters; rotation is valid only if every character in the string has a mapping. Rotating a whole string means:
-
reverse the string, and
-
replace each character
c
with
rot(c)
.
Return true if either:
-
t
as-is is a valid base-10 integer in
[1, 200]
, OR
-
rotate180(t)
is a valid base-10 integer in
[1, 200]
.
Assume the rotation map is provided as a dictionary (examples from the interview note included):
-
'6' <-> '9'
-
plus any additional pairs given at runtime (e.g.,
'h' -> '4'
,
'L' -> '7'
).
Characters not in the map are invalid for rotation.
Examples (assuming map includes 6<->9, 0->0, 1->1, 8->8):
-
"69"
rotates to
"69"
and is valid (
69
in range) ->
true
-
"201"
is out of range, rotate may or may not help -> depends on mapping -> compute
Task D — Track request begin/end times and print in a required order
You are implementing a Server class that receives events for requests. Each request has a unique requestId.
You must implement two methods:
-
begin(requestId, timestamp)
-
end(requestId, timestamp)
Part 1
Whenever both timestamps for a request are known, print/log a line:
-
requestId begin=<beginTs> end=<endTs>
Assumptions:
-
Events may arrive out of order (an
end
can arrive before
begin
).
-
There may be multiple in-flight requests.
Follow-up
Instead of printing immediately when a pair is complete, the server must always print completed requests in increasing order of end time (earliest end printed first). If multiple have the same end time, break ties by requestId.
Design the data structures and logic to support this ordering efficiently.