Challenge - 5 Problems
Sorted Set Rank Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find the rank of a member using ZRANK
Given a sorted set with members and scores, what is the rank of member 'apple' using ZRANK?
Redis
ZADD fruits 10 apple 20 banana 15 cherry ZRANK fruits apple
Attempts:
2 left
💡 Hint
ZRANK returns the zero-based rank of the member ordered from lowest to highest score.
✗ Incorrect
The sorted set 'fruits' has 'apple' with score 10, which is the lowest score, so its rank is 0.
❓ query_result
intermediate2:00remaining
Find the reverse rank of a member using ZREVRANK
Given a sorted set with members and scores, what is the reverse rank of member 'banana' using ZREVRANK?
Redis
ZADD fruits 10 apple 20 banana 15 cherry ZREVRANK fruits banana
Attempts:
2 left
💡 Hint
ZREVRANK returns the zero-based rank of the member ordered from highest to lowest score.
✗ Incorrect
The sorted set 'fruits' has 'banana' with the highest score 20, so its reverse rank is 0.
📝 Syntax
advanced2:00remaining
Identify the error in using ZRANK with a non-existing member
What is the output of the command ZRANK fruits orange if 'orange' is not a member of the sorted set?
Redis
ZADD fruits 10 apple 20 banana 15 cherry ZRANK fruits orange
Attempts:
2 left
💡 Hint
ZRANK returns nil if the member does not exist in the sorted set.
✗ Incorrect
Since 'orange' is not in the sorted set, ZRANK returns nil indicating no rank.
❓ query_result
advanced2:00remaining
Compare ZRANK and ZREVRANK outputs
Given the sorted set fruits with scores, what are the outputs of ZRANK fruits cherry and ZREVRANK fruits cherry?
Redis
ZADD fruits 10 apple 20 banana 15 cherry ZRANK fruits cherry ZREVRANK fruits cherry
Attempts:
2 left
💡 Hint
ZRANK orders from lowest to highest score, ZREVRANK from highest to lowest.
✗ Incorrect
'cherry' has score 15, which is the middle score. So rank is 1 and reverse rank is also 1.
🧠 Conceptual
expert3:00remaining
Understanding rank behavior with duplicate scores
If a sorted set has members with duplicate scores, how does ZRANK determine the rank of a member?
Attempts:
2 left
💡 Hint
Redis sorts members with the same score by their member name in alphabetical order.
✗ Incorrect
When scores tie, Redis orders members lexicographically by their member name to assign ranks.