## 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);
}``````

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++;
}
}
}``````

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( ) );}``````

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( ) );
}``````

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);

}``````

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);

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(); } } {{{ } }}} }}}
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

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());

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.

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

Time Complexity O(n) Space Complexity O(1)

``````def removeOdd(arr):
ind = 0
for i in range(len(arr)):
if arr[i] % 2 == 0:
arr[ind], arr[i] = arr[i], arr[ind]
ind += 1

return arr[:ind]``````

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>();
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);
}
}
}``````

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>();
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);
}
}
}``````

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>();
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--;
}
}``````

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.

### 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.