I know you've solved the problem, but I'm bored. Would this work? I
was never good at analysing time constraints
Given an array
n_1
n_2
...
n_k
create another array called sums:
n_1
n_1 + n_2
n_1 + n_2 + n_3
n_1 + n_2 + n_3 + ... n_k
Take two indices min and max
min = 0 max = f;
while max < L
Of course, the index numbers lower than the book being checked out,
don't need to be changed, just the higher numbers.
I like using an array of structs with structure members which can
group all the relevant data together that I want for that book, or
student, etc.
So Books[] might have: title,
how about a doubled linked list where you can remove item at any
index. the removing is O(1). you can also keep track of the current
size S so if you are borrowing book at index greater than S/2, you
traverse the list from the end, if index < S/2, you traverse from the
beginning.
every time a boo
To Adak,
The problem is that the numbers are not consecutive in values. So 3
can be got from 6 subtracts 2 and 7 is added in.
I got an idea from a friend on how to find max/min values on queues in
constant time with insertion and deletion in constant times as well.
By applying that idea to here
Darn it, I meant to post "Sticker shock", but my typo left out the
't'. .
Thanks for the clarification, Sticker.
I believe your algo can be tweaked a bit by simply adjusting your
substring's info when you need to "go back" to the start
of a substring. That is, when you drop the 2 from the substr