Head-Inserted Linked-List Hash Chain
Problem statement
valueHashes[i] is the already-computed hash of the value inserted on operation i. Insert each new node at the head of a linked list.
A node's stored hash equals its own value hash plus the stored hash of its next node; a missing next node contributes zero. Return the head's stored hash after every insertion.
Do not mutate valueHashes. Every returned value fits in a signed 64-bit integer.
Function
secureHeadHashes(valueHashes: int[]) → long[]Examples
Example 1
valueHashes = [5,7,2]return = [5,12,14]The successive head hashes are 5, 7+5, and 2+12.
Example 2
valueHashes = [0,0]return = [0,0]Zero-valued hashes keep the chain hash at zero.
Example 3
valueHashes = []return = []No insertions produce no head hashes.
Constraints
0 <= valueHashes.length <= 200000.0 <= valueHashes[i] <= 10^9.- The sum of all values fits in a signed 64-bit integer.