Challenge - 5 Problems
Blockchain Data Structures Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Solidity mapping example?
Consider the following Solidity code snippet. What will be the value of
balances[0x123] after execution?Blockchain / Solidity
pragma solidity ^0.8.0; contract Wallet { mapping(address => uint) public balances; function deposit() public { balances[msg.sender] += 100; } function test() public { deposit(); } }
Attempts:
2 left
💡 Hint
Think about what happens when deposit() is called by the sender.
✗ Incorrect
The deposit function adds 100 to the sender's balance. Calling deposit() inside test() increases balances[msg.sender] by 100. So balances[0x123] will be 100 if 0x123 calls test().
🧠 Conceptual
intermediate1:30remaining
Which data structure is best for constant time membership checks in smart contracts?
In blockchain smart contracts, which data structure allows you to check if an element exists in constant time (O(1))?
Attempts:
2 left
💡 Hint
Think about how mappings work in Solidity.
✗ Incorrect
Mappings in Solidity provide O(1) access to values by keys, making membership checks very efficient compared to arrays or linked lists.
🔧 Debug
advanced2:30remaining
Why does this Solidity code cause a runtime error?
Examine the following Solidity code. Why does calling
getValue(5) cause a runtime error?Blockchain / Solidity
pragma solidity ^0.8.0; contract Test { uint[] public values; constructor() { values.push(10); values.push(20); } function getValue(uint index) public view returns (uint) { return values[index]; } }
Attempts:
2 left
💡 Hint
Check the size of the array and the index used.
✗ Incorrect
The array 'values' has only 2 elements at indices 0 and 1. Accessing index 5 causes an out-of-bounds runtime error.
📝 Syntax
advanced1:30remaining
Which option correctly declares a fixed-size byte array in Solidity?
Select the correct syntax to declare a fixed-size byte array of length 4 in Solidity.
Attempts:
2 left
💡 Hint
Remember Solidity has a special type for fixed-size byte arrays.
✗ Incorrect
In Solidity, 'bytes4' declares a fixed-size byte array of length 4.
🚀 Application
expert3:00remaining
How many items are stored after this Solidity struct array operation?
Given the following Solidity code, how many
Person structs are stored in the people array after execution?Blockchain / Solidity
pragma solidity ^0.8.0; contract PeopleList { struct Person { string name; uint age; } Person[] public people; function addPeople() public { people.push(Person("Alice", 30)); people.push(Person("Bob", 25)); people.pop(); people.push(Person("Charlie", 20)); } }
Attempts:
2 left
💡 Hint
Remember what the pop() function does to the array.
✗ Incorrect
The code pushes Alice and Bob, then removes the last element (Bob), then adds Charlie. So the array has Alice and Charlie, total 2.