Bloomberg L.P.

  www.bloomberg.com
Work in HR? Unlock Free Profile

Bloomberg L.P. 2013 Financial Software Developer Interview Question

I interviewed in New York, NY and was asked:
"unsorted integer array size n. unmodifiable list of "less than" / "greater than" operators. place elements from int array in between each "<" and ">" operator so that every comparison holds true. e.g. 6, 2, 8, 1, 3, 9, 4, 0, 5, 7 <, >, <, <, <, >, <, >, > answer: 0 < 9 > 1 < 2 < 3 < 8 > 4 < 7 > 6 > 5"
Add Tags [?]
Answer

Part of a 2013 Financial Software Developer Interview Review - one of 1,741 Bloomberg L.P. Interview Reviews

Answers & Comments

0
of 1
vote
#include <iostream>

using namespace std;

bool compare(int data[], const char* optrs, const int& sz) {
    int temp;
    for (int i = 0 ; i < sz - 1 ; i++) {
        switch(optrs[i]) {
        case '<':
            if (data[i] > data[i+1]) {
                temp = data[i];
                data[i] = data[i+1];
                data[i+1] = temp;
                return false;
            }
            break;
        case '>':
            if (data[i] < data[i+1]) {
                temp = data[i];
                data[i] = data[i+1];
                data[i+1] = temp;
                return false;
            }
            break;
        }
    }
    return true;
}

int main() {

    const int MAX_DATA_SIZE = 10;
    char optrs[] = "<><<<><>>";
    int data[MAX_DATA_SIZE] = {6,2,8,1,3,9,4,0,5,7};

    while(!compare(data, optrs, MAX_DATA_SIZE)) {
        //Assuming the array data has a solution,
        //Include code here to check for when there is no solution!
    }

    for (int i = 0 ; i < MAX_DATA_SIZE - 1 ; i++)
        cout << data[i] << optrs[i];
    cout << data[MAX_DATA_SIZE -1] << endl;

    return 0;
}
- Juan Andrango on Sep 27, 2013
0
of 0
votes
Is this the same as a bubble sort, except you need to check each sign, instead of a universal one?
- Anonymous on Oct 28, 2013

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.