Interview Question






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

How can I sort a map by its .second parameter.Write the C++ code.

- Posch December 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. loop through the map using iterator
2. look at each value and compare to the search value
3. delete the key-value pair in the map that matches the search value
4. break out of loop immediately
5. put the search value in the map using a new / updated key

Time efficiency is O(n) or better. If there is faster algorithm, please reply to this.

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

I am not sure if understood this question right...let me know if i am doing some thing wrong:

Following are unique pairs with the same value:
1,10
2,10
3,10
4,10

if we try to find a value based on value 10, we would not be getting one key right?

- AlgosLearner December 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Mr.AlgosLearner, It is given in the question "assuming all key,value pairs are unique".

- Anonymous March 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Create a parallel map<value,key>. When a key needs to be modified for a given value, look up the key in this map<value,key>. Then update both map<value,key> & map<key, value>.

- ND_hates_datastage December 28, 2010 | 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