IPO Share Allocation
Learn this problemProblem statement
An initial public offering (IPO) refers to the process of offering shares of a private corporation to the public in a new stock issuance. Public share issuance allows a company to raise capital from public investors. IPO process can go through a typical auction, and an IPO price is not set before the auction. Potential buyers are able to bid for the shares they want and the price they are willing to pay. The bidders who were willing to pay the highest price are then allocated the shares available.
Before the auction ends, potential buyers can submit bids containing: user Id, number of shares, bidding price, timestamp. Once all the bids are submitted, the allotted placement is assigned to the bidders from the highest bids down, until all of the allotted shares are assigned. The auction assigns shares in multiple rounds until all shares are allocated or no more bids. In each round, it finds the bids with highest prices, assigns the shares, and removes the assigned bids:
- If the bid (with the highest price) has only 1 bidders, the bidder gets shares he/she bids for (or get whatever left if the unallocated shares are less than the bid shares);
- If the bids (with the highest price) have multiple bidders, the bidders are assigned shares as follows: Shares are distributed round robin style (i.e. one share per bidder in sequence until shares are all allocated) to bidders in the same price group, with the bidders sorted by timestamp. Once a bidder gets the number of shares they bid for, they will be removed from the above iterative process and the process which then continues until all bidders are removed or the shares get exhausted, whichever comes first.
Find out all bidders (user IDs) with no share allocation.
Complete the function getResults in the editor below. The function must return a list of integers, each an Id for those bidders who receive no shares, sorted ascending.
getResults has the following parameter(s):
bids[bids[0],...bids[n-1]]: a 2D array of arrays of integers,Id,shares,price,timestampnamedu,sc,bp,tsgoing forwardtotalShares: an integer, the total shares to allocate
Function
getResults(bids: int[][], totalShares: int) → int[]Examples
Example 1
bids = [[1,2,5,0],[2,1,4,2],[3,5,4,6]]totalShares = 3return = [3]There are totalShares = 3 shares among the 3 bidders. The first 2 shares are allotted to the user with Id 1 as it has the highest bidding price. The 3rd share is allotted to the user with Id 2 as it is the first user, based on timestamp, in the bidding group having the bidding price 4. The only bidder who doesn't receive shares has user Id of 3.
Constraints
1 ≤ n < 10^41 ≤ u, sc, bp, ts, totalShares < 10^8