This question evaluates understanding of symmetric shared-secret string transformation and the design of a randomized set supporting expected O(1) operations, testing skills in cryptographic string manipulation and data-structure algorithmic reasoning.
You are asked about two coding topics from an onsite interview:
s
of lowercase English letters and a non-empty lowercase key
k
s[i]
, shift it forward in the alphabet by
k[i % k.length] - 'a'
positions, wrapping around from
z
to
a
s = "attack"
,
k = "dog"
"dhzdqq"
O(1)
time:
insert(val)
: add
val
if it is not already present; return whether the insertion happened
remove(val)
: remove
val
if it is present; return whether the removal happened
getRandom()
: return a uniformly random element currently in the set