## Bloomberg LP Interview Questions

- 0of 0 votes
Write a program to accept a nonempty string of alphanumeric characters. Define a “run” as a

consecutive sequence of a single character. For example, “aaaa” is a run of length 4. The program will

print the longest run in the given string. If there is no single longest run, then you may print any of

those runs whose length is at least as long as all other runs in the string.

Example input: a

Example output: a

Example input: aab

Example output: aa

Example input: abbbbbcc

Example output: bbbbb

Example input: aabbccdd

Example output: aa

- 0of 0 votes
Write a program to accept a nonempty string of 0's and 1's as an argument. The program will print the

offsets of runs, each run consisting of all 0's or all 1's, where the runs are longer than 1. For example, if

given "0010011" it will print "0, 3, 5" on stdout.

- 0of 0 votes
For an N-ary Tree find the nearest common ancestor.

Given: rootid and a function which finds and returns the immediate parent of a node.

- 0of 0 votes
For an N-ary Tree find the nearest common ancestor.

Given: rootid and a function to find the immediate parent of a node.

- 0of 0 votes
Given a set of integer dots (like (1,5)), how can you find a pair that has an integer mid-point? For example, (1,1) and (3,3) have an integer mid-point of (2,2), while (1,1) and (3,2) do not. Tell the complexity of your code. What if the dots are N-dimensional?

- 1of 1 vote
Find first unique number in an unsorted array of 32 bit numbers without using hash tables or array of counters.

- 0of 0 votes
There is a large data file with 10 digit numbers. You are allowed to use only 20 megabytes of memory. How would you sort them ?

- 0of 0 votes
Find the longest repeating character in a sorted string

- -1of 1 vote
Player turns are stored in an array like so [1,2,1,2,1,2,1,2]. Make it so that player 1 finishes first and then player 2. i.e [1,1,1,1,2,2,2,2]

- 0of 0 votes
An array contains the following elements [9,6,-3,1,7] and a value is equal to 4. Find a pair of numbers in the array that equal the sum.

- 0of 0 votes
How do you implement stack in stl? What is the complexity?

- 1of 1 vote
I have 5 arrays with integer elements. I want to find the common elements in all 5 arrays. What is the logic?c

- 0of 0 votes
What is smart pointer? How do you implement? What happens with the following: p2 = p1;

What happens P3(p1) (copy const)?

- 0of 0 votes
Picture a restaurant kitchen with tickets of customer’s orders which has a start time, end time of when the order was completed, and price. How would you find the longest contiguous time that tickets were processed within a given day?

- 0of 0 votes
Websites like Pandora recommend music based on user preferences. What kind of information would you need in such a design?

- 1of 1 vote
Given an integer, print out all the prime numbers smaller than that integer.

- 2of 2 votes
Given a binary tree, find out the maximum sum of value from root to each leaf.

`find_Max(Node *root){ if (root==null) return 0; else return max((find_Max(root->left), find_Max(root->right))+root->value; }`

- 2of 2 votes
Find the largest k numbers in an enormous array of numbers. You cannot sort the array. Give the run time of the algorithm.

- 3of 3 votes
Given an integer N, print numbers from 1 to N in lexicographic order.

Details: To be implemented without using character conversion (or Strings).

Example:

N = 25

Print:

1

10

11

..

19

2

20

21

..

25

3

4

5

6

7

8

9

A simple solution using Strings (may not be acceptable):`System.out.print("\n\tLexicographic Order\n\nEnter an integer: "); Scanner input = new Scanner(System.in); Integer n = input.nextInt(); List<String> list = new ArrayList<String>(); for (int i = 1;i<n;i++){ list.add(""+i); } Collections.sort(list); for (String j: list){ System.out.println(j); }`

- 0of 0 votes
What are virtual constructors and virtual destructors?

- 0of 0 votes
In code there is a breakpoint at the first line of main function. The program is executed but it crashes without touching the breakpoint. Is there any code that is executed before main itself

- -2of 2 votes
Given historical data for the stocks of a company for say 8 day. you can buy and sell the stocks just once. Find the maximum profit you can make:

Day 1 2 3 4 5 6 7 8

5 9 6 2 4 8 3 1

- 0of 0 votes
Given a string 'aabbcdccefff', find the first Non-duplicate character i.e. 'd'

- 6of 6 votes
Q: If you have all the companies that are traded, and live inputs are coming of which company is being traded and what is the volume, how do you maintain the data, so that you can carry out operation of giving the top 10 most traded companies by volume of shares most efficiently.

A: I juggled between Hash Map and Max Heap. I said Max Heap, since I can take out top 10 companies in a jiffy with a Max Heap. But then he asked you will need to find a company everytime there is a trade, which will take quite some time in Heap. He pointed out that in real world scenario, number of trades happening, and hence searching of the company and updating it, will be many times more than finding top 10. Which bought me to HashMap. Updations can happen in Real time, while finding top 10 can be done in O(n) or O(nlog(n)) time.

Even that wasn't optimal obviously. The interviewer was very nice and friendly type guy. He stressed that at every trade, at most, only 1 company will change in my top 10. This hit me and got me to the correct answer that we keep all actual data in HashMap, but also maintain a MinHeap of 10 most traded company.

- 2of 2 votes
Q: If I give you a new book, and ask you to create the index which is found at the end of the book, how will you do it.

A: I said for constant addition time of words (and page numbers) in the data structure, we can use Hashmap or TRIE. But since output has to be in alphabetic order, we will use a Trie DS, where at the end of each word, we simple store a list of page numbers.

- 1of 1 vote
Q: The New operator...how does it work, what are the steps?

A: I just said it creates a new memory in the heap and the reference points to it. He seemed satisfied.

- 1of 1 vote
Q: Do you know what is a Binary tree? How would you go about coding for addition of a new element to Binary tree?

A: I asked if they want a Binary Tree or a BST? When he said BST I just said we can have a recursive function in which we pass the root of the tree and see if the value to be added is smaller or bigger than the root, and depending on result, we go to left or right of the tree, assuming the left (or right) is not null. If null, just use new to create a memory location, put the value, and use the left reference of the root to link to this new memory. Simple basic stuff.

- 2of 2 votes
Q: Do you know what is a stack? Explain

A: Yes, explained LIFO push pop peek

Q: In stack, Push and Pop are constant. What will you do if you want an operation which gives the min of the stack also in constant time?

A: Question is straight out of Gayle's Book. You just maintain a new stack of minimum number till that point.

- 0of 0 votes
3 Baskets, with label Apple Orange and Mixed. All the lables are incorrect. Pick up one fruit from one of the 3 baskets and find the correct labels for these 3 baskets.

- 0of 0 votes
How to find a missing value in an size N unsorted array (value from 0 to N but missing one of them).