In the technologically advanced North Pole, Santa decided to streamline his gift-tracking system using URL query parameters, entrusting the elves with entering present requests. However, the mischievous Grinch added duplicate parameters like "present=puzzle" and "present=unicorn" as a prank. On Christmas Eve, as Santa set out to deliver gifts, the excess parameters caused a glitch: the list of names entered an infinite loop.
Santa has some lists of names that are becoming too long to deal with. Help him by adding URL query parameters for paginating the list.
The task is to create a POST endpoint /5
that takes a JSON list of names, and query parameters offset
and limit
as numbers. Then, return the sub-slice of the list between index offset
and offset + limit
.
curl -X POST "http://localhost:8000/5?offset=3&limit=5" \
-H 'Content-Type: application/json' \
-d '[
"Ava", "Caleb", "Mia", "Owen", "Lily", "Ethan", "Zoe",
"Nolan", "Harper", "Lucas", "Stella", "Mason", "Olivia"
]'
["Owen", "Lily", "Ethan", "Zoe", "Nolan"]
This time, Santa also needs to be able to get all pages at once.
Modify the same endpoint, so that it can also handle a split
parameter. All parameters should now be optional. If not given, offset
defaults to 0, and limit
defaults to including all remaining items in the list. If split
is not given, no splitting will happen, but if given, the output list should be split into sub-lists with length according the the value.
curl -X POST http://localhost:8000/5?split=4 \
-H 'Content-Type: application/json' \
-d '[
"Ava", "Caleb", "Mia", "Owen", "Lily", "Ethan", "Zoe",
"Nolan", "Harper", "Lucas", "Stella", "Mason", "Olivia"
]'
[
["Ava", "Caleb", "Mia", "Owen"],
["Lily", "Ethan", "Zoe", "Nolan"],
["Harper", "Lucas", "Stella", "Mason"],
["Olivia"]
]
curl -X POST "http://localhost:8000/5?offset=5&split=2" \
-H 'Content-Type: application/json' \
-d '[
"Ava", "Caleb", "Mia", "Owen", "Lily", "Ethan", "Zoe",
"Nolan", "Harper", "Lucas", "Stella", "Mason", "Olivia"
]'
[
["Ethan", "Zoe"],
["Nolan", "Harper"],
["Lucas", "Stella"],
["Mason", "Olivia"]
]
Authors: joshua-mo-143, jonaro00
You can now run our test cases against your locally running project with the official validator!