Wednesday, October 12, 2016

Sample Interview Questions


Round 1

  1. Look at Bloomberg ticker.  What can you tell me about this instrument
    1. IBM 10 P150 Equity
      1. It's a put option on ibm equity with 150 strike price
    2. When does it expire?
      1. 10/2016
    3. What day?
      1. third friday of the month
  2. Assume IBM stock is priced at 155.  Calculate the MV of 1000 standard contracts of the option above if it were a Call
    1. 1000 contracts * 100 shares * (155 price - 150 strike price) = 500,000
  3. Assume you have compliance rules that specify certain tickers you cannot trade.  These rules are specified at the firm level and at the fund level.  Firm level restrictions apply to all funds.  Write a query that shows all the funds and restricted tickers for each fund.
    1. select FundID, Ticker from Fund cross join Restrictions where FundID is null
    2. union 
    3. select FundID, Ticker from Restrictions where not FundID is null
  4. You are given a table of ticker, date, and daily P&L.  Find the top 10 tickers for each date by P&L.
    1. select * from (select date, ticker, rank = dense_rank() over (partition by date order by dailypnl desc) ) X where rank<=10
  5. You are given an array that represents a maze.  0 = space, 1 = wall, 2 = exit, 3 = start.  How would you write a program that solves the maze?
  6. In a hand of texas hold-em, you have two tens.  your opponent has queen, 9.  The flop shows J, 10, 8.  What is the probability of winning?


Round 2
  1. Design a database with the following data entities and constraints:
    1. DataEntities
      1. User - properties: user name
      2. Address - properties: street, city, state
      3. Order - properties: amount
      4. Office Location - properties: location name
    2. Constraints:
      1. User must have an address
      2. No two users can have the same address
      3. Every order has a user
      4. Not every user has an order
      5. User may have any number of office locations, including zero
    3. Solution:
      1. Users table has Primary key of User ID and a nullable address ID column with a Foreign Key and a unique constraint on address ID
      2. Address table has a primary key of address id
      3. Orders table has primary key of order id and non-nullable foreign key of user id.
      4. Office location table has primary key of office id
      5. UserOffice table has composite primary key of (userid, officeid) and foreign keys to user and office tables.
  2. Write a query and results based on tables in question 1 that would give name of all users, order id and amount of any orders for those users.  E.g. Username, Order ID, Amount
    1. Table Data:
      1. User
        1. ID = 1, Name = U1
        2. ID = 2, Name  = U2
        3. ID = 3, Name = U3
      2. Order
        1. ID = 101, UID = 1, Amount = 10
        2. 102, 2, 20
        3. 103, 1, 30
        4. 104, 2, 40
        5. 105, 1, 50
        6. 106, 2, 60
    2. Solution:
      1. Query
        1. select a.UName, b.OID, b.Amount
        2. from user a
        3. left join order b
        4. on a.UID=b.UID
        5. order by a. UNam, b.OID, b.Amount
      2. Results
        1. U1 , 101, 10
        2. U1, 103, 30
        3. U1 , 105, 50
        4. U2, 102, 20 
        5. U2 , 104,40
        6. U2 , 106,60
        7. U3, NULL, NULL
  3. Write a query and results based on tables and data in question 1 & 2 that would give name of all users and total amount of any orders for those users
    1. Solution:
      1. Query:
        1. select a. UName, total = Sum(Amount)
        2. from user a
        3. left join order b
        4. on a.UID=b.UID
        5. group by a. UName
      2. Results
        1. U1, 80
        2. U2, 120
        3. U3, NULL
  4. Same as question 3, except only show users where total is greater than 100
    1. Solution
      1. Query:
        1. select a. UName, total = Sum(Amount)
        2. from user a
        3. left join order b
        4. on a.UID=b.UID
        5. group by a. UName
        6. having sum(Amount)>100
      2. Results
        1. U2, 120
  5. Same as question 3, except there's a new user with a duplicate name: ID=4, Name=U1 and a new order: ID=107, UID=4, Amount = 100.  Ensure each unique user has their own total.
    1. Solution:
      1. Query:
        1. select a. UName, total = Sum(Amount)
        2. from user a
        3. left join order b
        4. on a.UID=b.UID
        5. group by a.UID, a. UName
      2. Results:
        1. U1, 80
        2. U2, 120
        3. U3, NULL
        4. U1, 100
  6. Write C# code that would give you the same output as question 3.  Assume you have C# objects with properties that are equivalent to columns in the tables.  Assume an object called DataService has methods getUsers() and getOrders() that return the user and order data, respectively.  
    1. Solution:
      1. see Main() below
  7. Same as 6 except assume the data set is now very large (e.g. # of users >100,000 and # orders > 1,000,000).  Hint: you will need a more efficient algorithm. 
    1. Solution:
      1. See Alternate() below

sample code for #6 and #7 

using System.Collections.Generic;

namespace MQuiz
{
  public class User
  {
  public int UID { get; set; }
  public string UName { get; set; }
  }
  public class Order
  {
  public int OID { get; set; }
  public int UID { get; set; }
  public float Amount { get; set; }
  }
  public class Program
  {
  public static void Main(string[] args)
  {
  var users = DataService.getUsers();
  var orders = DataService.getOrders();
  foreach (User u in users)
  {
  bool isMatched = false;
  foreach(Order o in orders)
  {
  if(u.UID == o.UID)
  {
  isMatched = true;
  System.Console.WriteLine(u.UName + " " + o.OID + " " + o.Amount);
  }
  }
  if(!isMatched) { System.Console.WriteLine(u.UName + " NULL NULL"); }
  }
  }
  public static void Alernative()
  {
  var users = DataService.getUsers();
  var orders = DataService.getOrders();

  var orderDictionary = new Dictionary<int, Dictionary<int, Order>>();
  foreach(Order o in orders)
  {

  Dictionary<int, Order> orderList;

  if (orderDictionary.ContainsKey(o.UID))
  {
  orderList = orderDictionary[o.UID];

  }
  else
  {
  orderList = new Dictionary<int, Order>();
  }

  orderList.Add(o.OID, o);

  orderDictionary.Add(o.UID, orderList);
  }

  foreach (User u in users)
  {
  if (orderDictionary.ContainsKey(u.UID))
  {
  var oDict = orderDictionary[u.UID];
  var o = oDict[u.UID];

  System.Console.WriteLine(u.UName + " " + o.OID + " " + o.Amount);
  }
  else
  {
  System.Console.WriteLine(u.UName + " NULL NULL");
  }

  }
  }
  }
  public static class DataService
  {

  public static List<User> getUsers() { return new List<User>(); }
  public static List<Order> getOrders() { return new List<Order>(); }
  }


}

No comments:

Post a Comment