This text file describes the activity in the line at Sam's ice cream shop yesterday.
When customers enter the line, they are arbitrarily assigned a number. This action is represented by the string "ENTER ###", where ### is the customer number.
When the customer at the front of the line receives their ice cream, they leave the line. This action is represented by the string "LEAVE".
Assume no customer leaves the line until they reach the front and receive their ice cream. If "LEAVE" appears when nobody is in line, there are no changes to the line.
Take this example:
ENTER 234
ENTER 142
ENTER 200
LEAVE
LEAVE
In this example, customers 234, 142, and 200 entered the line. Then 234 left, followed by 142. In the end, only customer 200 was still in line.
Click here to open the text file describing the line activity yesterday. Assume the line was empty to begin with.
Let S be the sum of the customer numbers who were still in line at the end of yesterday. What are the last 3 digits of S ?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The full answer 99563, and the last three digits are 563 .
To solve this, use a queue data structure to represent the line at Sam's. Every time a new customer enters, push their number onto the end of the queue. When a customer leaves, pop the value at the front of the queue.
At the end of the queue manipulation, sum up the customer numbers in the queue.