Bloomberg Interview | Set 2 (Video Conference)

Click here to see the documentation of the first phone interview.

The video conference came after passing the phone interview, it was held on Skype with 2 interviewers from Bloomberg: Freddy and Chad.

The call started by both of them introducing themselves, and so did I, and I was, again, asked to say what I know about bloomberg, and why I want to work there.

The interviewers then jumped to the first question, it was direct, for the following code, answer the given 9 questions.

#include <string.h>
int main(int argc, char *argv[])
    char    abc[27];
    char    *ptr = abc;
    strcpy(abc, "abcdefgxyz");
     * What are the types and values of expressions:
     * 1. abc
     * 2. *abc
     * 3. abc[2]
     * 4. &abc[3] //&abc[3] = abc + 3*sizeof(char)
     * 5. abc+4
     * 6. *(abc+5) + 20000  //h  long long x = int * 1LL * int
     * 7. abc[10] //'\0'
     * 8. abc[12] //memset ()
     * 9. &ptr //char**
     return 0;

The second question was as follows:

The shown code is built to print out the current date, but for some reason, it doesn’t.
You are required to figure out the reason.

#include <stdio.h>
#include <string.h>
#include <time.h>
char *get_date()
    char    buf[80];
    time_t  now = time(0);
    strcpy(buf, ctime(&now));
    return buf;

int main(int argc, char *argv[])
    char *date = get_date();
    printf("date=%s\n", date);
    return 0;

At the beginning the code looked fine to me, the only thing I thought would be the problem, is the declaration of the char array buf on the stack instead of the heap.
So, I suggested that dynamic allocation should solve the problem and that we should use malloc(80*sizeof(char)) instead of buf[80]
The interviewers said it was the correct step, but he still needs a reason.
The interviewers gave a hint, that in case a breakpoint was set just before the printf if, the debugger shows that date does hold the correct result, so the problem is in printf.
After I had enough time, the interviewer decided to give me the answer to move next.
The problem was that when printf is called, it needs a part of the stack, and this may affect the stack-reserved array of characters buf.

The next question was a follows:
Given an integer n, return the number of ways it can be represented as a sum of 1s and 2s, order matters.

I suggested we use a recursive function to compute it.
And then suggested to use some sort of memoization.
The code was as follows:

// number of ways 
// n = 3
// 3 = 1,2
// 1,1,1,
// 2,1

int memo[1000000]; // memset (memo, -1, sizeof(memo));
int ways_of_sum_up(int n)
    if (n == 0)
        return 1;
    if (n < 0)
        return 0;
    if (memo[n] != -1)
        return memo[n];
    int ans = ways_of_sum_up (n-1) + ways_of_sum_up (n-2);
    return memo[n] = ans;

I then realized the problem forms linear recurrence, where f(n) = f(n-1) + f(n-2), so it can be solved using matrix exponentiation.
I spend around 15 minutes explaining the solution to the interviewers, and they didn’t seem to understand a word of it.

f(0) = 1
f(1) = 1

f(n) = f(n-1) + f(n-2)

[1 1][f(n)]         [f(n)+f(n-1)]
[1 0][f(n-1)]     [f(n)]

[1 1]^m
[1 0]

x^y  =  x^(y/2) * x^(y/2) = x^(y/4) * x^(y/4) * x^(y/4) * x^(y/4) 
     = ...... = x^1 ............ x^1

x^5 = x^2 * x^2 * x

[1 1]^2     [1 1]^1     x*x
[1 0]       [1 0] 

The running time complexity of the solution is O(log(n)), same as the memory complexity.

There was another solution that I didn’t have time to say, which has a time complexity of O(n) and a memory complexity of O(1), which models this problem to the fibonacci problem.

The last question was so trivial, I was asked to reverse a string in place, I used the 2 pointers, here was the code:

// "hello world" -> "dlrow olleh"

void reverse_word( char* str, int size )
    int p1, p2;
    p1 = 0;
    p2 = size-1;
    while (p1 < p2){
        char tmp = str[p1];
        str[p1] = str[p2];
        str[p2] = tmp;

Finally I was asked to use this code to reverse words within a sentence, in place, here was the code:

// "hello world" -> "world hello"
//    "hello world" -> "dlrow olleh"
// "hello there everyone" -> "everyone there hello"

// "hello" -> ?

void reverse_sentence( char* str, int size )
    int p1;
    p1 = 0;
    //"hello world"
    reverse_word (str, size); //linear
    //"dlrow olleh"

    //"world olleh"
    //"world hello"

    for (int i=0;i<size;i++){
        p1 = i;
        while (p1 < size && str[p1] != ' ')
        reverse_word (str + i*sizeof(char), p1-i);
        i = p1;

Result: Rejected.

Summary: The interviewers are not so good with problem solving, they are good implementers just it, so type neat and clean code, use the obvious ideas, don’t do complicated solutions, because they most probably won’t get it.
If I made one mistake in this interview, I would say it was using matrix exponentiation rather than the easier linear-time constant-memory solution.
Good Luck with that, passing this video conference means you are going to London for an onsite, final interview, so you have another reason to do your best.

If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Write your Interview Experience or mail it to

Practice Tags :

Recommended Posts:

3 Average Difficulty : 3/5.0
Based on 1 vote(s)