You are on page 1of 3

Quiz questions

0. Title: Maps 01
Description: Which of the following is true about maps?

0.They are internally implemented as self-balancing binary search trees.


1.We can access elements stored in a map using the [ ] operator.
2.All of them
3.They store key, value pairs ordered on the basis of keys.

1. Title: Maps 02
Description: You need to store how many students scored some particular marks in
the JEE MAINS out of 320(assume only positive marks can be scored). Which of the
following is the most efficient?

0.A map where key is the score obtained and value is the number of students who got
this score.
1.a hashmap where key is the score obtained and value is the number of students who
got this score.
2.Store all student data in an array and simply loop throught to find students who
scored a particular score.
3.An array of 321 elements where marks[i] = x denotes x students got i marks.

2. Title: Maps 03
Description: Now imagine you need to store the number of people with a particular
net worth. which of the following is a good way to do that.

0.Still an array will be the most efficient way to the required info.
1.A map but only because it is not a good practice to use arrays.
2.A vector instead of an array should be used.
3.A map because it will require less memory.

3. Title: Maps 04
Description: Predict the output :

0.5 1
1.2 1
2.Runtime error because of an attempt to insert a duplicate key.
3.Runtime error because the key 3 does not exist in the map.

4. Title: Maps 05
Description: Which of the following will give a compile-time error?

0.map < pair < int, int >, pair<string, int > > myMap;
1.map < set< int >, pair< string, int > > myMap;
2.map < map < string, int >, long long > myMap;
3.None of them
5. Title: Maps 06
Description: What is the difference between Map and MultiMap associative
containers?

0.A map allows only unique keys wheras a multimap can have duplicate keys.
1.A map allows only unique values wheras a multimap can have duplicate values.
2.A multimap is made-up of maps.
3.It is possible to create many copies of multimap but not in the case of a map.

6. Title: Maps 07
Description: How will you efficiently print the largest key in a map?

0.You will need to traverse till there to do that.


1.mp.rbegin()->second;
2.mp.rbegin()->first;
3.put all keys in a vector and sort it then use the last element of the vector.

7. Title: Maps 08
Description: What does the following code do?
vector< string > func(vector< string > paraGraph, int ct)

map< string, int > myMap;


vector< string > someWords;
for(string word : paraGraph)
myMap[word] ++;

for(auto it = myMap.rbegin(); it !=
myMap.rend() && ct; it++)
someWords.push_back(it->first); ct--;
return someWords;
}

0.returns random words present in the input paraGraph string.


1.returns ct words that come last in lexographic ordering of the words present.
2.returns the least frequently occuring ct words.
3.returns the top frequently occuring ct words.

8. Title: Maps 09
Description: The following data type map < keyType, vector < valueType > > myMap :

0.Can be used as a multimap.


1.Can be used both as a vector and a map
2.Can be used as a trie.
3.Can be used as a segment tree.
9. Title: Maps 10
Description: You are given N three-dimensional points in space. The ith point has
the coordinate x, y and z. Each point is either red or black. 0 <= x,y,z <= 100.

You need to store this information and also return the color corresponding to the
point P(X,Y,Z) on demand, if P(X,Y,Z) is present in the N points.

Which of the following data structures can be used?


choose the most efficient in terms of space and time complexity.

0.bool points[101][101][101], if points[x][y][z] = 1 then point x,y,z is red else


black.
1.map< pair < int , pair < int, int > >, bool > points;
2.map< pair < int , pair < int, int > >, int > points;
3.None of these.

You might also like