Suppose we have a list of strings called book, if we page an index (0-indexed) into the book, and page_size, we have to find the list of words on that page. If the page is out of index then simply return an empty list.
So, if the input is like book = ["hello", "world", "programming", "language", "python", "c++", "java"] page = 1 page_size = 3, then the output will be ['language', 'python', 'c++']
To solve this, we will follow these steps −
l:= page*page_size
return elements of book from index l to l+page_size - 1
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, book, page, page_size): l=page*page_size return book[l:l+page_size] ob = Solution() book = ["hello", "world", "programming", "language", "python", "c++", "java"] page = 1 page_size = 3 print(ob.solve(book, page, page_size))
Input
["hello", "world", "programming", "language", "python", "c++", "java"], 1, 3
Output
['language', 'python', 'c++']