Feature #3: Goals Fulfilled

Implementing the "Goals Fulfilled" feature for our "Stocks" project.

We'll cover the following

Description

Our stock trading company is hiring interns. Different interns start on different days. Each intern is given a target to close at least three trades on any given day and log these trades using automatically incrementing sequence numbers. Each intern will close trades numbered 1, 2, 3, .... Since different interns have spent a different number of days on the job at any given time, one may be closing trade number 2 while another is closing trade number 23.

Before you arrived, a developer wrote a logging application for the interns. The application accepts trades sequence numbers from the interns and stores them in a centralized log. The logs keep separate records for each day. Unfortunately, the developer didn’t include the intern IDs in the log records. To complicate matters further, the developer sorted the list of trade numbers before storing it in the log. For example, consider a day on which three interns were working. They logged the following trades: [1, 2, 3, 4], [4, 5, 6] and [10, 11, 12]. The log for this day would say [1, 2, 3, 4, 4, 5, 6, 10, 11, 12].

Given a day’s record log, we want you to figure out if every intern working on a given day submitted at least three deals for the day or not as accurately as possible. Note that if the log said [1, 2, 3, 4, 5, 6, 10, 11, 12], we can’t be certain if there were three interns working or two. However, all we are interested in is a true/false answer, which would be true in the above case. If on a given day, there is no way that any number of interns could have reported at least three deals, return false.

We’ll be provided with a list of sorted numbers representing trades. This list actually contains the different sets of trades made by interns organized in a sorted manner. Our task is to determine if subsequences/sets with at least three consecutive elements exist in them or not.

Here is an illustration to better understand this:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.