Challenge - 5 Problems
LRANGE Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What does this LRANGE command return?
Given a Redis list
mylist with elements ["a", "b", "c", "d", "e"], what is the output of the command LRANGE mylist 1 3?Redis
LRANGE mylist 1 3
Attempts:
2 left
💡 Hint
Remember that LRANGE uses zero-based indexing and includes both start and end positions.
✗ Incorrect
LRANGE returns elements from the start index to the end index inclusive. Index 1 is 'b', index 3 is 'd', so the result is ['b', 'c', 'd'].
❓ query_result
intermediate1:30remaining
What is the output of LRANGE with negative indices?
If
mylist contains ["x", "y", "z", "w"], what does LRANGE mylist -3 -1 return?Redis
LRANGE mylist -3 -1
Attempts:
2 left
💡 Hint
Negative indices count from the end of the list, starting at -1 for the last element.
✗ Incorrect
Index -3 corresponds to 'y', and -1 corresponds to 'w'. LRANGE returns elements from 'y' to 'w' inclusive.
📝 Syntax
advanced1:00remaining
Which LRANGE command is syntactically correct?
Identify the syntactically valid LRANGE command to get elements from index 2 to 4 from list
mylist.Attempts:
2 left
💡 Hint
LRANGE syntax requires the key followed by two separate integer arguments for start and stop.
✗ Incorrect
Only option D uses the correct syntax: LRANGE key start stop with spaces separating arguments.
❓ optimization
advanced2:00remaining
Efficiently reading the last 5 elements of a large list
You have a Redis list
biglist with 1 million elements. Which LRANGE command efficiently retrieves the last 5 elements?Attempts:
2 left
💡 Hint
Negative indices are a convenient way to access elements from the end without calculating exact positions.
✗ Incorrect
Using negative indices like -5 to -1 directly accesses the last 5 elements without needing to know the list length.
🧠 Conceptual
expert1:30remaining
What happens if LRANGE start index is greater than end index?
Consider a Redis list
mylist with elements ["p", "q", "r"]. What is the result of LRANGE mylist 2 1?Attempts:
2 left
💡 Hint
LRANGE returns elements from start to end index inclusive, but start must be less or equal to end.
✗ Incorrect
If start index is greater than end index, LRANGE returns an empty list without error.