Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef Solution_h
- #define Solution_h
- #include <iostream>
- #include <string>
- #include <map>
- std::multimap <std::string, int> shoeSize =
- {
- { "James", 41 },
- { "Raz", 41 },
- { "Fisnik", 43 },
- { "Mikaela", 39 },
- { "James", 41 },
- { "AMujtaba", 41 },
- { "AMujtaba", 41 },
- { "James", 41 } };
- class Solution {
- public:
- Solution() {
- int s1; //Should be 41
- std::string s2; //Shoule be "James"
- s1 = findSize();
- s2 = findName();
- std::cout << s1 << std::endl;
- std::cout << s2 << std::endl;
- }
- int findSize() {
- // Find/return the most popular shoe size in the given list of shoe sizes and associated names. If there is no uniquely popular shoe size, return -1.
- int n = 0;
- int size = 0;
- for (auto elem : shoeSize) {
- if (shoeSize.count(elem.first) > n) {
- n = shoeSize.count(elem.first);
- size = elem.second;
- }
- }
- return (n < 1) ? -1 : size;
- }
- std::string findName() {
- //Find/return the most popular name for the most popular shoe size.
- //If there is no uniquely common name, OR if there is no uniquely popular shoe size, return an empty string. Names are case sensitive.
- std::string name = "";
- int n = 0;
- for (auto elem : shoeSize) {
- if (shoeSize.count(elem.first) > n) {
- n = shoeSize.count(elem.first);
- name = elem.first;
- }
- }
- return name;
- }
- };
- /*
- Shoe Sizes
- Overview
- Your task is to implement two (2) functions which process some data. Below we will go through the task you are required to solve. First, you will be presented with a description of the problem task. Then we will present the data available to you to solve the problem. In the last section, we give you an explanation of how scores are being calculated.
- Make sure to read the entire description before attempting the problem.
- Task Description
- Your task is divided into two parts. You will have data accessible through our API for solving the problems. This is further described in the API Description section.
- Problem 1): popular_size
- Find/return the most popular shoe size in the given list of shoe sizes and associated names. If there is no uniquely popular shoe size, return -1.
- Problem 2): popular_name
- Find/return the most popular name for the most popular shoe size. If there is no uniquely common name, OR if there is no uniquely popular shoe size, return an empty string. Names are case sensitive.
- In the above example, the answer to question 1 would be 41 - and the answer to question 2 would be 'James'.
- Canvas Description
- Canvas Explained
- API Description
- The following data is available for you to access through the API provided. Details about the API functions and the data they provide can be found under the API tab.
- List Length
- The number of names and associated shoe sizes available to you for the given level.
- Name
- The name of a person at a given list index.
- Size
- The shoe-size of a person at a given list index.
- Scoring
- Focus on getting the correct output, as this is the major part of the scoring (80%). You can see your points for each level in the canvas on the bottom right when you press ‘Run code’. Note that your code will be assessed using hidden levels of different configurations. Ensure your code works for all scenarios.
- 20% of your score is calculated through time-complexity analysis of your solution, so if you have time try to consider how to make your solution as efficient as possible.
- */
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement