Bloomberg LP Interview Question for Financial Application Engineers


Country: United States
Interview Type: In-Person




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

1. take an array of size 256 and initialize it to zero.
2. scan the input string from beginning and increment corresponding index of array(ie array[input string[i] ]++ ).
3. scan the input string from beginning and check 1 == array[input string[i] ]. if such exist, input string[i] will be the answer.

- Vin September 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hI I have tried the solution in vc++.Please find the code for the question.I have not done unit testing and little care is taken for efficiency.
#include"stdafx.h"
#include<iostream>
using namespace std;

void first_duplicate(char*p)
{
int i,j,count=0;
i=0;
j=1;
int index=0;
while(p[index] != '\0')
{
while(p[i] == p[j])
{
count++;

i++;
j++;

}
if(count)
{
i =j;
j = j+1;
count=0;

}
else if(count ==0)
{
cout<<"fist duplicate found @ "<<p[i]<<endl;
break;
}
index++;
}
}
int main()
{
char string[40]="aabbbbccceeeddffsssk";
first_duplicate(string);
getchar();
return 0;


}

- Anonymous September 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String b="aabbcdccefff";
        char[] ca=b.toCharArray();
        Arrays.sort(ca);
        int i,j,k;
        for(i=0,j=1,k=2;k<ca.length-1;i++,j++,k++){
            if(ca[i]!=ca[j]&&ca[j]!=ca[k]&&ca[i]!=ca[k]){
                System.out.println(ca[j]);
                return;
            }
        }

It's O(nlogn) complexity if not sorted else it can be obtained in O(n)

- nithindextrous September 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

public class Test{

public static void main(String[] args){

String str = "aabbcdcceefff";
int[] arr = new int[26];
int temp = 0;

for(int i=0;i<str.length();i++){

arr[str.charAt(i)-'a']++;
}

for(int i=0;i<str.length();i++){
if(arr[i] == 1){
temp = i;
break;
}
}
System.out.println(temp);
int a = temp + 'a';
char b = (char) a;
System.out.println(b);
}
}

- Ankit September 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Test{

public static void main(String[] args){

String str = "aabbcdcceefff";
int[] arr = new int[26];
int temp = 0;

for(int i=0;i<str.length();i++){

arr[str.charAt(i)-'a']++;
}

for(int i=0;i<str.length();i++){
if(arr[i] == 1){
temp = i;
break;
}
}
System.out.println(temp);
int a = temp + 'a';
char b = (char) a;
System.out.println(b);
}
}

- Learner September 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

The interviewer gave that example??
That example is sh*t.
Because it has d as answer... but there are two interpretations.
d is the first letter in alphabet with that property AND
d is the first letter in the string with that property

The hiring manager => Loser.

- bigphatkdawg September 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;

public class UniqueLetterInString {
	public static void main (String args[]) {
		String[] inputString={"a","a","b","b","c","d","d","c","c","e","f","f","f"};
		int i,j=0;
		HashMap duplicateCount=new HashMap();
		
		for(i=0;i<inputString.length;i++)
		{
			
				if(duplicateCount.containsKey(inputString[i]))
				{
					int count=Integer.parseInt(duplicateCount.get(inputString[i]).toString());
					count++;
					duplicateCount.put(inputString[i], count);
				}
				else
				{
					duplicateCount.put(inputString[i], 1);
				}
				System.out.println("Key ---->"+inputString[i]+"Value--->"+Integer.parseInt(duplicateCount.get(inputString[i]).toString()));
		}
		Iterator itr =duplicateCount.entrySet().iterator();
		while(itr.hasNext())
		{
			Map.Entry pairs = (Map.Entry)itr.next();
			if(Integer.parseInt(pairs.getValue().toString())==1)
			{
				System.out.println("The character which is unique is -->"+pairs.getKey());
				break;
			}
		}
			
	}
}

- TestUser September 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

String str ="aabbcdcceefff";
for (int i=0;i<str.length();i++){
if(str.indexOf(str.charAt(i))==str.lastIndexOf(str.charAt(i))){
return str.charAt(i);
}
}

- harsha September 26, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think this is O(n) implementation, i ve run it and it works!

#include <iostream>
#include <string>
#include <cctype>
#include <utility>
#include <limits>

int main () {
	std::string s = "aabbcdccefff";
	std::string::const_iterator iter = s.begin();
	int i = 0;	
	int array[26];
	for (i = 0; i < 26; ++i) {
		array[i] = 0;
	}

	for (i = 1; iter != s.end(); ++iter, ++i) {
		int index = (int) *iter - 'a';
		if (array[index] == 0) {
			array[index] = i;
		} else if (array[index] > 0) {
			array[index] *= -1;
		}
	}

	int min_value = std::numeric_limits<int>::max();
	int min_index = -1;
	for (i = 0; i < 26; ++i) {
		if (array[i] > 0) {
			if (array[i] < min_value) {
				min_value = array[i];
				min_index = i;
			}
		}
	}

	std::cout << (char) (97 + min_index) << std::endl;
}

- vaticanoptimist September 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I'm not assuming the characters are necessarily lowercase:

import java.util.*;

class FirstNonDuplicate
{
    public static void main( String [] args ) 
    {
        LinkedHashMap<Character, Boolean> map = new LinkedHashMap<>();

        for( Character c : args[0].toCharArray() )
        {
            Boolean alreadyFound = map.get( c );

            if( map.get( c ) == null )
                map.put( c, true );
            else if( alreadyFound == true )
                map.put( c, false );
        }

        Iterator<Character> iterator = map.keySet().iterator();

        Boolean found = false;
        while( iterator.hasNext() && !found )
        {
            Character c =  iterator.next();
            found = map.get( c );

            if( found )
                System.out.println( c );
        }


    }
}

- Isaac October 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream> // std::cout
#include <algorithm> // std::find_if
#include <string> // std::vector

int main ()
{
std::string input = "aabbcdccefff";

for(std::string::iterator itr = input.begin(); itr != input.end(); ++itr)
{
char _in = *itr;
if (1 == std::count(input.begin(), input.end(),_in))
{
std::cout << "First duplicate value: " << _in << '\n';
break;
}
}
return 0;
}

- Vaibhav January 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class findFirstNonDuplicate {

	public static void main(String[] args) {
		String s ="aabbcdccefff";
		char x = 0;int i;boolean flag = true;
		for( i = 0;i<s.length();i++){
			x = s.charAt(i);
			for(int j =0;j<s.length();j++){
				if(i!= j && x == s.charAt(j)){
					flag = false;
					continue;
				}
			}
			if(flag == true){
				System.out.println("First Non Duplicate Occurence: "+x);
				break;
			}
			flag = true;
		}	
	}
}

- karpagaganesh March 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In Ruby (tested with 2.1.1)

string_to_parse = ARGV[0]

def find_first_unique_char_in_string str
  return "" if str.nil? || str.empty?
  char_hash = Hash.new(0)

  # because they aren't ordered, go through each char
  str.each_char{|c| char_hash[c] += 1}

  # print the key for the first char that appears one time
  puts char_hash.select{|k,v| v ==1}.keys.first
end

find_first_unique_char_in_string string_to_parse

- dkerchner May 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <string.h>

static const char*
find_unique(const char *string);

#define MAP_SIZE (256)
#define DUP ((char*)-1)
#define EOS ((char)0)

main() {

    char *string = "aabbcDccefff";
    const char *unique;

    unique = find_unique(string);
    if(unique)
	printf("unique character at 0x%lx => %c\n", unique, *unique);
}

static const char*
find_unique(const char *string) {

    const char *char_map[MAP_SIZE];
    const char *c;

    memset(&char_map, 0, sizeof(char_map));

    for(c = string; *c != EOS; ++c) {
	if(*c == EOS)
	    break;

	char_map[*c] = char_map[*c] ? DUP : c;
    }

    for(c = string; *c != EOS; ++c) {
	if(char_map[*c] != DUP)
	    return c;
    }

    return NULL;
}

- Glenn September 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

This is the C++ version of harsha's response

#include <iostream>

using namespace std;

int main() {

	string data = "aabbcdccefff";

	for (int i = 0 ; i < data.length() ; i++) {
		if (data.find_first_of(data.at(i)) == data.find_last_of(data.at(i))) {
			cout << "answer: " << data.at(i) << endl;
			break;
		}
	}
}

- asdf September 27, 2013 | 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