Citadel

Initial Public Offering

A. IPO (Braze Version)

1. The bidder with the highest price gets the number of shares they bid for 2. If multiple bidders have bid at the same price, the bidders are assigned shares in the order in which they placed their bids (earliest bids first)

#sort twice
#time:O(nologn)
#bids: id, num, price, time
import collections
def solution(bids, total):
    #init hash
    bids.sort(key = lambda x:(-x[2],x[3]),reverse = True)
    res = []
    while total>0:
        bid = bids.pop()
        print(bid)
        total -= bid[1]
        print(total)
    while bids:
        res.append(bids.pop()[0])
    return res


if __name__ == "__main__":
    #print(solution([[1, 2, 5, 0], [2, 1, 4, 2], [3, 5, 4, 6]],3))
    print(solution([[1, 5, 5, 0],[2, 7, 8, 1],[3, 7, 5, 1],[4, 10, 3, 3]],18))

B. IPO

1. The bidder with the highest price gets the number of shares they bid for 2. If multiple bidders have bid at the same price, the bidders are assigned shares as follows: Each bidder in the same price group gets assigned once share each consecutively, with each bidder being arranged inside the group based on their timestamps. Once a bidder gets the number of shares they bid for, they will be removed from above iterative process and the process which then continues until all bidders are removed or the shares get exhausted, whichever comes first.

Matrix Summarization (Before and After Matrix)

Last updated