Head-Inserted Linked-List Hash Chain
Updated
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 change 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.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Insert After a Linked-List NodeAMD · ONSITE INTERVIEW
- Process Singly Linked List OperationsSEDEMAC · ONSITE INTERVIEW
- Calculate Server Shutdown PenaltyStripe · PHONE SCREEN · ONSITE INTERVIEW
- LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEW
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEW
- LFU CacheSnowflake · OA · ONSITE INTERVIEW
- LRU Cache with TTLAutodesk · ONSITE INTERVIEW
- Least Recently Used CacheMicrosoft · OA · PHONE SCREEN · ONSITE INTERVIEW
- Recover a Function-Call LRU Cache with a Write-Ahead LogAnthropic · ONSITE INTERVIEW