about | help | code help+videos | done | prefs |
Write a method that accepts an array called 'books' that represents a stack of books with page numbers indicated by the value in the array. The book numbers start at 1, so the book in books[0] is book #1. You are also given a page that you want to identify in the stack called 'pageStack'. Imagine that the books are stacked with book #1 on the bottom, followed by book #2, then book #3, etc. Each book has a number of pages indicated by the value in the correct position in the array. We will ignore the covers of the book and only consider the pages. Your goal is to tell which book you need to go to and which page in that book you need to go to in order to have 'pageStack' number of pages stacked that high. For example, if 'books' is {20,50,70} that means that book #1 has 20 pages, book #2 has 50 pages, and book #3 has 70 pages. If 'pageStack' is 30, you would return {2,10} meaning that you have to go to page 10 in book #2 to get 30 pages stacked. If 'pageStack' is 74, you would return {3,4} because you would have to go to page 4 of book 3 to get 74 pages stacked. If there are not enough pages in all the stacked books, return [-1,-1] as an error code. Look at the test data for more examples. test2024_02_08_HL_bookAndPage([700], 800) → [-1, -1] test2024_02_08_HL_bookAndPage([20, 40, 60, 20, 10, 5, 15], 500) → [-1, -1] test2024_02_08_HL_bookAndPage([50, 20, 100, 70], 75) → [3, 5] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 260
Copyright Nick Parlante 2017 - privacy