Phone Interview Question from some company: Portfolio Management

YOU are given a portfolio of stocks and ETFs, and a stock name, both of whcih are in String format. Calculate how many shares of the stock the portfolio has.
E.g
"{30GOOGLE, 50AMZN, 20MSFT, 100S&P500{2GOOGLE, 5FB, 10INTEL}, 40ETF1{5S&P500, 10GOOGLE}}" , "GOOGLE"
The total numbe of shares of GOOGLE is :
30 + 100X2 + 40X(5X2 + 10) = 1030 Shares of GOOGLE

Explanations:

  1. The name of a stock or ETF can only begin with a capitailized letter. The name may contain digits or special characters (e.g "S&P500").
  2. An EFT may contain both stocks and other ETFs.
  3. 40ETF1{5S&P500, 10GOOGLE} means we have 40 shares of ETF1, and each each share of ETF1 contains 5 shares of S&P500 and 2 shares of GOOGLE.
Comments (0)