You are conducting an IPO auction to allocate a fixed number of shares to potential investors.
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 the 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, and 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 gets whatever is 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 will then continue until all bidders are removed or the shares get exhausted, whichever comes first.
You are given:
totalShares: an integer representing the total number of shares available.bids: a list of bids, where each bid is represented as[userId, sharesRequested, bidPrice, timestamp].
Return the list of bidders with no share allocation, sorted in the ascending order of userId.
Constraints:
- 0 <
totalShares≤ - 0 <
bids.length≤ sharesRequested,bidPrice> 0timestampis unique within the input
Example 1:
Input: bids = [[1, 1, 101, 0], [1, 2, 100, 1], [2, 4, 100, 2], [3, 1, 99, 3], [4, 2, 100, 4]], totalShares = 3 Output: [3, 4] Explanation:
- Price 101: User 1 (t=0) is allocated 1 share. Remaining: 2.
- Price 100: Users 1 (t=1), 2 (t=2), and 4 (t=4) are in this group. Sorted by time: User 1, User 2, User 4.
- Round 1: User 1 gets 1 share, User 2 gets 1 share. Remaining: 0.
- User 4 gets 0 shares.
- Price 99: User 3 (t=3) gets 0 shares because shares are exhausted.
Therefore, User 1 has 2 shares, User 2 has 1 share, User 3 and User 4 have 0 shares.
Example 2:
Input: bids = [[1, 10, 100, 5], [2, 10, 90, 1]], totalShares = 5 Output: [2]
Example 3:
Input: bids = [[1, 2, 100, 1], [2, 2, 100, 2]], totalShares = 3 Output: []
