Bloomberg LP Interview Question for Financial Software Developers






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

The ideal is to have two stack. One which will store elements and the other which will store min elements till now

eg: Add 10

	10  10
	
Add 20

	20  10
	10  10
	
Add 30

	30 10
	20 10
	10 10
	
Add 5

	 5  5
	30 10
	20 10
	10 10

Add 3

	 3  3
	 5  5
	30 10
	20 10
	10 10

Minimum Till now is top of 2nd Stack ie 3

Remove 3

	 5  5
	30 10
	20 10
	10 10

- Snehal January 10, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

O(n) shouldn't be a problem. can we get any better?

- Anonymous June 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

T min(stack <T> s)
{


}

- Anonymous June 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

T min(stack <T> s)
{
T t = T.Max();
stack <T> s1;
while(!s1.empty())
{
if (s1.top() < t)
t = s1.top();
s1.push(s1.top());
s.pop();
}
while(!s1.empty())
{
s.push(s1.top());
s1.pop();
}
return t;


}

- Anonymous June 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can have each element in the stack to maintain a min Element below the stack.
Whenever a new element is added we check if the element is lesser than the Min below the Top of stack and if so we make the min Element below the new element being added as the element itself(As it is for the first element itself).

- Anonymous June 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Tricky part,
What If Min() is called twice?

- Anonymous July 10, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

pop all elements out and save them into an array.

- Anonymous June 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

keep track of the min value within the current in stack in its topmost element.

- Anonymous September 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What if I did pop() and then min ??

Our algo will produce erroneous output . Am I right ?

- Subrahmanyam February 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;
import java.util.Collections;
import java.util.Stack;


public class C {

public static void main(String[] args) {

Stack<Integer> st = new Stack<Integer>();
ArrayList<Integer> list = new ArrayList<Integer>();

st.push(12);
st.push(15);
st.push(6);
st.push(2);
st.push(23);
st.push(18);

while(!(st.isEmpty())){

int top = st.pop();

list.add(top);
}

System.out.println(list);

Collections.sort(list);

System.out.println(list.get(0));
}

}

- Anonymous August 19, 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