Q1 You're starting a new day as a trader at Optiver and you're experiencing a short squeeze. At the same time, to remain a designated market maker, you're obligated by the stock exchange to perform at least 2n transactions. This is a very risky situation, and you want to minimize those risks. You decide to perform exactly 2n transactions of 1 share each. You are starting the day with a 0 position in this stock and you need to end the day with a 0 position as well. Because of the short squeeze, the stock is impossible to borrow, meaning your position can never be negative. Given n, how many different ways are there to perform the 2n transactions to achieve your goals? For example if n=2 there are two ways of achieving 0 position by the end of the day that never put you in a negative share state: buy-sell-buy-sell and buy-buy-sell-sell.
Q2 Market participants submit "buy" and "sell" orders at various prices, forming an order book. When a new "buy" order at a price p is submitted, one of two scenarios can occur:
There exists a "sell" order in the order book at a price lower or equal to p. In this case, a transaction occurs at a price of that "sell" order between the two market participants, and both orders are removed from the order book. If there are two or more orders in the order book that could result in a trade, the one with the better (lower) price will take priority.
There is no "sell" order in the order book at a price lower or equal to p. In this case the "buy" order is added to the order book.
Analogously, if a "sell" order is submitted and there exists a viable "buy" order in the order book, a transaction will occur at the highest viable price. If not, the order is added to the order book.
Orders are encoded as a 2-element integer array. The first element takes values of +1 or -1 indicating buy or sell order, respectively. The second element represents the price.
Given a sequence of orders, return the sum of prices across all transactions that occurred.