Feature #2: Settling Period
Understand how to implement the settling period in stock trading scenarios, ensuring no two trades for the same stock occur within the cooldown interval. Learn to calculate the minimum total time required to execute all trades by analyzing trade frequencies and idle intervals, a crucial skill for tackling stock-related coding interview problems.
We'll cover the following...
Description
The settling period is the time that must elapse before money changes hands after a stock trade is completed. We don’t want to allow another trade in the same stock before the expiry of the settling period. So, a person can’t trade more than one stock of the same company at once, and the user must wait for the settling period before another stock of the same company can be traded.
We are given a list of letters, where each letter represents the stock of a company for which a stock trade must be made. The stocks will be mapped to letters to form this input array. Letters can repeat to represent that multiple trades need to be made for the same company’s stocks. We want to make all the given trades as quickly as possible. The constraint is that two trades of the same company must be separated by at least k intervening periods; these could be trades of other companies or idle periods. The parameter k defines the settling period. We need to calculate the minimum amount of time required to trade all the stocks.
For example, if a user wants to trade four stocks of APPLE, two stocks of TESLA and one stock of MICROSOFT ...