🧠 Google Interview Experience - Round 1
Hi everyone 👋
I got this question in a Google interview, and I found it quite interesting — it's like a hybrid between a linked list and a blockchain. I'd love to get your thoughts on:
What is this data structure best called?
What’s a clean and optimal way to implement it?
Is there a similar problem on LeetCode or anywhere else?
🔐 Problem Statement
You’re given a secured linked list where each node contains:
data: a string
next: pointer to the next node
hashValue: an integer
There’s a given hash(String input) function that returns an integer hash. You can use this function but cannot modify it.
🔁 Hash Rule
Each node’s hashValue is computed as:
If it’s the last node:
hashValue = hash(data)
Otherwise:
hashValue = hash(data + next.hashValue)
This creates a forward-dependent hash chain, meaning if any node changes, all previous hashes become invalid.
✅ Tasks to Implement
Node insertAtPosition(String data, int position, Node head)
Inserts a new node at the given position.
Recalculates hashValue for all affected nodes.
Returns the (possibly new) head.
boolean isChainValid(Node head)
Verifies that each node's hashValue follows the rule above.
Returns true if the chain is valid, false otherwise.
❗ Tampering Scenario
If a hacker inserts a node at position p without updating any hashes, isChainValid() should detect that the chain has been compromised.
🧱 Node Definition
class Node {
String data;
Node next;
int hashValue;
Node(String data) {
this.data = data;
this.next = null;
this.hashValue = 0; }
}
❓ What I’d Love Input On
What kind of data structure would you call this?
Is there a known pattern like this (blockchain-inspired, Merkle-ish)?
Would you solve this recursively or iteratively?
Any similar problems on LeetCode or other platforms to practice?
Thanks in advance for your thoughts and insights! 🙌


