0
0
Blockchain / Solidityprogramming~20 mins

Efficient data structures in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Blockchain Data Structures Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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();
    }
}
A100
B0
CCompilation error
DUndefined
Attempts:
2 left
💡 Hint
Think about what happens when deposit() is called by the sender.
🧠 Conceptual
intermediate
1: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))?
AMapping
BArray
CLinked List
DBinary Tree
Attempts:
2 left
💡 Hint
Think about how mappings work in Solidity.
🔧 Debug
advanced
2: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];
    }
}
AType error because values is not an array
BCompilation error due to missing return statement
CIndex out of bounds error because index 5 does not exist
DNo error, returns 0
Attempts:
2 left
💡 Hint
Check the size of the array and the index used.
📝 Syntax
advanced
1: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.
Abyte[4] data;
Bfixed bytes data = 4;
Cbytes data[4];
Dbytes4 data;
Attempts:
2 left
💡 Hint
Remember Solidity has a special type for fixed-size byte arrays.
🚀 Application
expert
3: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));
    }
}
A1
B2
C3
D0
Attempts:
2 left
💡 Hint
Remember what the pop() function does to the array.