Challenge - 5 Problems
Sorted Set Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this ZRANGE command?
Given a sorted set
myzset with elements {"one":1, "two":2, "three":3, "four":4}, what does the command ZRANGE myzset 1 2 return?Redis
ZRANGE myzset 1 2
Attempts:
2 left
💡 Hint
ZRANGE returns elements by rank starting at 0, inclusive.
✗ Incorrect
ZRANGE returns elements by their rank in ascending order. Index 1 is "two", index 2 is "three".
❓ query_result
intermediate2:00remaining
What is the output of this ZREVRANGE command?
Given a sorted set
myzset with elements {"one":1, "two":2, "three":3, "four":4}, what does the command ZREVRANGE myzset 0 1 return?Redis
ZREVRANGE myzset 0 1
Attempts:
2 left
💡 Hint
ZREVRANGE returns elements by rank in descending order starting at 0.
✗ Incorrect
ZREVRANGE returns elements starting from the highest score. Index 0 is "four", index 1 is "three".
📝 Syntax
advanced2:00remaining
Which command correctly returns elements with scores included?
You want to get elements and their scores from
myzset using ZRANGE. Which command is correct?Attempts:
2 left
💡 Hint
The option to include scores is a single word.
✗ Incorrect
The correct syntax is WITHSCORES as one word without spaces.
❓ optimization
advanced2:00remaining
How to efficiently get the top 3 highest scored elements with scores?
Which command is the most efficient to get the top 3 elements with highest scores and their scores from
myzset?Attempts:
2 left
💡 Hint
Top highest means descending order starting at 0.
✗ Incorrect
ZREVRANGE with 0 2 returns top 3 elements in descending order efficiently.
🧠 Conceptual
expert2:00remaining
What happens if you use negative indexes in ZRANGE?
Given
myzset with 5 elements, what does ZRANGE myzset -3 -1 return?Redis
ZRANGE myzset -3 -1
Attempts:
2 left
💡 Hint
Negative indexes count from the end backwards.
✗ Incorrect
Negative indexes in ZRANGE count from the end, so -3 to -1 returns last 3 elements in ascending order.