Back to problems

Target Stock Portfolio Operations

Algorithm · Optiver · Medium

You begin with initial shares of a stock and want to finish with target shares. Each operation is one of the following: Buy one share, increasing your holdings by 1. Sell one share, decreasing your holdings by 1. You may use no more than m operations. Your holdings must never become negative, so selling is not allowed when you have 0 shares. Return the number of distinct operation sequences that finish with exactly target shares and contain at most m operations. Constraints…

Checking your access…