Bloomberg LP Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

public int maxProfit(int[] arr){
	int maxP = 0;
	int minElement = arr[0];
	if(arr.length==0)
		return maxP;
	for(int i=1;i<arr.length;i++){
		if(arr[i]>minElement){
			if(maxP <(arr[i]-minElement))
				maxP = arr[i]-minElement;
		}else{
			minElement = arr[i];
		}
	}
	return maxP;
}

- Joe May 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

in Scala:

object MaxProfitSingleBuy {
  
  def main(args: Array[String]): Unit = {   
    val a = Array(100, 120, 150, 180, 200, 40, 56, 90, 280)    
    println(getMaxProfitSingleBuy(a))
  }   
    
  def getMaxProfitSingleBuy(a:Array[Int]) : Int = {        
    var i = 0  
    var j = 0
    var max = -1
    var maxI = -1
    var maxJ = -1
    
    while (i < a.length - 1) {            
      while (i < a.length-1 && a(i) > a(i + 1)) i += 1
      
      j = i + 1
      while (j < a.length-1 && a(j) < a(j + 1)) j += 1
      
      // found local maxima
      if (a(j) - a(i) > max) {            
        max = a(j) - a(i)
        maxI = i
        maxJ = j
      }
      
      i += 1
    }
    return max
  }
  
}

- guilhebl May 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

in Javascript:

function getMaxProfit(stockPrices) {
    // sort array ascending numerically
    stockPrices.sort((x, y) => { return (x - y); });
    return (stock_prices[stock_prices.length - 1] - stock_prices[0]);
}

- Seth June 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

double maxProfit(std::vector<double> & prices)
{
    double minSoFar = std::numeric_limits<double>::max();
    double maxProfit = 0;
    for( auto const& price: prices)
    {
        double CurrentMaxProfit = price - minSoFar;
        maxProfit = std::max(CurrentMaxProfit, maxProfit);
        minSoFar= std::min(price, minSoFar);        
    }    
    return maxProfit;
}

- steephen June 28, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Do indices in the stock array indicate time? Like every stock price at every minute? or are we trying to just get the max profit of the given values?

- JustYourAverageDev July 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int MaxProfit(vector<int> const &prices)
{
    int max_profit = 0;
    int buy_price = numeric_limits<int>::max();
    for (int price : prices) {
        if (price < buy_price) {
            buy_price = price;
        } else {
            max_profit = max(max_profit, price - buy_price);
        }
    }
    return max_profit;
}

- Alex August 15, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More