Bloomberg LP Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

void DeleteOdd(vector<int> &a)
{
	int i = 0;
	for (int n : a) {
		if (n % 2 == 0) {
			a[i++] = n;
		}
	}
	a.resize(i);
}

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

void DeleteFromVector(vector<int> &V)
{
	auto B = V.begin();

	while (B != V.end())
	{
		if ((*B) % 2)
		{
			B = V.erase(B);
		}
		else
		{
			B++;
		}
	}
}

- Girish with the Fetish April 15, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is it cheating to use a standard library algorithm?

void deleteOdd( vector<int> & v )
{
v.erase( std::remove_if( v.begin( ), v.end( ), [](int i) {return i%2; } ), v.end( ) );}

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

void deleteOdd( std::vector<int> & v )
{
  auto pred = []( int i ) -> bool { return i % 2; };
  auto first = find_if( v.begin( ), v.end( ), pred );
  for ( auto last = first; last != v.end( ); ++ last )
    if ( ! pred( * last ) )
      * first ++ = * last;
  v.erase( first, v.end( ) );
}

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

void deleteOdd(vector<int>&nums)
{
    int j=nums.size()-1;
    for ( int i=0;i<nums.size(); i++)
    {
        if ( i == j )
            break;
        while( (nums[i] % 2 )  )
        {
            swap(nums[i],nums[j--]);
        }
       
    
    }
    nums.resize(j);

}

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

int[] arr = new int[] { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
List<int> IntegerList = arr.ToList();
var removeList = IntegerList.RemoveAll(m => m % 2 != 0);

- chinmay8116 May 07, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
{{{ int delete(List<Integer> nums){ Iterator<Integer> it = nums.listIterator(); while(it.hasNext()){ if(it.next()%2 !=0){ it.remove(); } } {{{ } }}} }}} - visualvm January 19, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The simple way is get a temporary index which is initial with 0; Look at code

// temporary index;
	index = 0;
	// go over array
	for (number in numbers) {
		if (number % 2 == 0) { // if number is even
			// you just say, for current index put me this number, which is not odd
			numbers[index++] = number;
		}
	}
	// the last tricky is update your length with index;
	numbers.resize(index)

That's all

- Eldan January 26, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

myVec.erase(std::remove_if(myVec.begin(), myVec.end(), [](int i){return i % 2 > 0; }), myVec.end());

- Anonymous February 12, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Most of the solutions here don't account for the O(n) operation for calling remove on the Vector/List/Array, effectively ending up with a O(n^2) solution.

- Barinder H April 09, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

import java.util.*;

public class Solution{
	public static void main(String[] args){
		List<Integer> nums = new ArrayList<Integer>();
		nums.add(1);
		nums.add(2);
		nums.add(3);
		nums.add(4);
		nums.add(5);
		nums.add(-6);
		nums.add(7);
		nums.add(8);
		nums.add(9);
		nums.add(10);
		deleteNum(nums);

	}
	public static void deleteNum(List<Integer> nums){
		for(int i=0;i<nums.size();i++){
			if(nums.get(i)%2 != 0){
				nums.remove(i);
			}
		}
		for(Integer s: nums){
			System.out.println(s);
		}		
	}
}

- Anonymous April 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

import java.util.*;

public class Solution{
	public static void main(String[] args){
		List<Integer> nums = new ArrayList<Integer>();
		nums.add(1);
		nums.add(2);
		nums.add(3);
		nums.add(4);
		nums.add(5);
		nums.add(-6);
		nums.add(7);
		nums.add(8);
		nums.add(9);
		nums.add(10);
		deleteNum(nums);

	}
	public static void deleteNum(List<Integer> nums){
		for(int i=0;i<nums.size();i++){
			if(nums.get(i)%2 != 0){
				nums.remove(i);
			}
		}
		for(Integer s: nums){
			System.out.println(s);
		}		
	}
}

- Anonymous April 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Joe's refactored variant:

public static void main(String[] args) {
		List<Integer> nums = new ArrayList<Integer>();
		nums.add(1);
		nums.add(1);
		nums.add(1);
		nums.add(1);
		nums.add(1);
		nums.add(1);
		nums.add(1);
		nums.add(1);
		nums.add(1);
		nums.add(10);
		deleteNum(nums);

	}

	public static void deleteNum(List<Integer> nums) {
		int index = 0;
		int count = nums.size();
		while (count > 0) {
			if (nums.get(index) % 2 != 0) {
				nums.remove(index);
			} else {
				System.out.println(nums.get(index));
				index++;
			}
			count--;
		}
	}

- ricoto April 14, 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