We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Kindergarten Adventures
Kindergarten Adventures
Sort by
recency
|
52 Discussions
|
Please Login in order to post a comment
My approach to solve in O(n) was to iterate through each i student's extra time and in another array, keep track of the range of where the teacher could start grading in which student i would have enough time to complete their drawing. Ranges should be able to overlap. The result gives us an array with overlapping ranges of starting points, and the value indicated in each index of the array should be equivalent to the number of drawings that would be finished if the teacher were to start there.
To calculate the range: We know that if given the maximum amount of extra time, the student will finish (unless t[i] == t.length, because the last student graded will only have t.length - 1 time to finish), so the range starts at i + 1, because that's a starting point where the student i will be graded last. The range continues up until the starting point where student i is graded with just the exact amount of extra time they need. Subtracting t[i] from i gives you the last spot in the range that a starting point would work. Since the students are in a circle, mod it by t.length to account for looping.
To keep track of the ranges, instead of incrementing every value in between the start and end of the range (this would be very time- consuming with very large numbers of students), you can also just increment the value at the start of the range and decrement the same value at the index after the end of the range. This way, when iterating through the range array, you will know at what point you've entered or left the range, and if you keep track of the largest sum, it is effectively going to be the maximum value of overlapping ranges.
Here's my solution in typescript: *note: Typescript mod operator is not a standard mod operation so I actually wrote up a method to perform what one would normally expect from mod, but for brevity I wrote this code up pretending that % works as expected
Here's my solution in Python. My basic idea is that when a student goes from being first to be visited by the teacher to being last, they gain len(t)-1 minutes, while all other students lose a minute. Instead of re-building a dictionary in every iteration, I use the fact that the student going from first to last gains len(t) minutes relative to all other students. Unless the student required 0 minutes, going from first to last guarantees that they will be able to finish their drawing, incrementing the count by 1. But then the count is decreased by the number of students who previously had just enough time. `from collections import deque def solve(t): completed = 0
this problem easily could be awarded with 100 points or even promoted as hard.
there are many things to consider:
Overall the advantage of kindergarten learning is the lifelong effects on a child's behavior. Kindergarten learning is not all about the foundation of school but it also marks a significance on your child's lifestyle and manners. So instead of merely relying on a local kindergarten school, you should explore Worksheets by No Fuss Tutors or other of its kind to land the best place for your child's learning.
My O(n) solution in C++. Here is my idea: 1. For each value of t[i], count all sastified starting points then store in an array. 2. Search for max element in array then return the index. To store and search effciently, you may try the problem Array Manipulation in Data structure - hard - array