Bloomberg LP Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

Using PHP for #4:

$arrays = array(array(0, -90, 45, 10, 4), array(4, 8, 90, 45), array(-1, -3, -5, -7, 10, 4), array(24, 35, 78, -90, 56, 4));


foreach ($arrays[0] as $ele) {
    $found = true;              
    for ($i = 1; $i < sizeof($arrays); $i++) {
        if (!in_array($ele, $arrays[$i])) {
            $found = false;
        }
    }    
    if ($found) {
        echo "\n First common element is: ". $ele."\n";
    }
}
if (!$found) {
    echo "\n There isn't any common element in all the arrays\n";    
}

- Bikash Rai April 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Testing if this shows as an answer

and this
	is {
		some code;
	}

- Robert Jones April 15, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//
// Pt 1
//
bool f( int array[ ], unsigned size );

//
// Pt 2
//
std::string asReadableList( const std::vector<int> & v )
{
  using namespace std;

  ostringstream os;
  auto begin = v.begin( ), end = v.end( );
  if ( ! v.empty( ) )
    os << * begin ++;
  for ( ; begin != end; ++ begin )
    os << "," << * begin;
  return os.str( );
}


//
// Pt 3
//
int minCommonPair( std::vector<int> & v, std::vector<int> & w )
{
  using namespace std;

  sort( v.begin( ), v.end( ) );
  sort( w.begin( ), w.end( ) );

  for ( auto iv = v.begin( ), iw = w.begin( ); iv != v.end( ) && iw != w.end( ); )
  {
    if ( * iv == * iw )
      return * iv;
    if ( * iv < * iw )
      ++ iv;
    else
      ++ iw;
  }
  // There is no common element.
  return 0; // Something!
}

//
//  Pt 4
//
int minCommonAny( std::vector<std::vector<int>> & v )
{
  using namespace std;

  // Sorted already.
  vector<vector<int>::iterator> begins( v.size( ) );
  vector<vector<int>::iterator>   ends( v.size( ) );
  transform( v.begin( ), v.end( ), begins.begin( ), []( vector<int> & v ) { return v.begin( ); } );
  transform( v.begin( ), v.end( ),   ends.begin( ), []( vector<int> & v ) { return   v.end( ); } );

  auto finished = [ & begins, & ends ] ( ) -> bool
  {
    for ( auto beginit = begins.begin( ), endit = ends.begin( ); beginit != begins.end( ); ++ beginit, ++ endit )
    {
      if ( * beginit == * endit )
        return true;
    }
    return false;
  };

  while ( ! finished( ) )
  {
    vector<int> minimums( v.size( ) );
    transform( begins.begin( ), begins.end( ), minimums.begin( ), []( vector<int>::iterator i ) { return * i; } );
    cout << "{ " << asReadableList( minimums ) << " }" << endl;
    int minmin = * min_element( minimums.begin( ), minimums.end( ) );
    int maxmin = * max_element( minimums.begin( ), minimums.end( ) );
    if ( minmin == maxmin )
      return minmin;
    for_each( begins.begin( ), begins.end( ), [maxmin]( vector<int>::iterator & it ) { if ( * it < maxmin ) ++ it; } );
  }
  // There is no common element... return something.
  return 0;
}

- robertgbjones April 16, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Pt 4

bool firstCommon(vector<vector<int>>& input, int& result) {
    int size = input.size();
    vector<vector<int>::iterator> first;
    for (int i = 0; i < size; ++i) {
        first.push_back(input[i].begin());
    }
    
    while(true) {
        int maxFirst = *(first[0]);
        for (int i = 1; i < size; ++i ) {
            if (*(first[i]) > maxFirst) {
                maxFirst = *(first[i]);
            }
        }
        
        bool found = true;
        for (int i = 0; i < size; ++i ) {
           if (*(first[i]) < maxFirst) { 
               if (++first[i] == input[i].end()) {
                   return false;
               }
               found = false;
           }
        }
        
        if (found) {
            result = maxFirst;
            return true;
        }
    }
}

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

int CommonElement(vector<vector<int>> const &arrays)
{
	int el = numeric_limits<int>::min();
	vector<int> idxes;
	idxes.resize(arrays.size(), 0);
	for (int i = 0; i < arrays.size(); ++i) {
		bool found = false;
		bool greater = false;
		while (idxes[i] < arrays[i].size()) {
			int n = arrays[i][idxes[i]];
			if (el == numeric_limits<int>::min() ||
				n == el)
			{
				el = n;
				found = true;
				break;
			}
			if (n > el) {
				el = n;
				found = true;
				greater = true;
				break;
			}
			idxes[i]++;
		}
		if (!found) {
			break;
		}
		if (greater) {
			i = -1;
		}
		if (i == arrays.size() - 1) {
			return el;
		}
	}
	return numeric_limits<int>::min();
}

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

#solution works for sorted arrays
def findFirstCommonElement(arr):
    for i in range(len(arr[0])):  #take the first array as reference
        val = arr[0][i]
        found = True

        for j in range(1, len(arr)):  # check through all the other arrays in the list
            for k in range(len(arr[j])):     
                if arr[j][k] == val:        
                    found = True
                    break
                elif arr[j][k] > val:    # if element  > the value being searched we can quit
                    found = False
                    break
            if found == False:   # if val not in 1 array no point in searching further
                break	          #check the next val
        if found == True:       # if val found in all arrays
            return val
    return -1

- Ron June 23, 2019 | 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