Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. #ifndef Solution_h
  2. #define Solution_h
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <map>
  7.  
  8. std::multimap <std::string, int> shoeSize =
  9. {
  10. { "James", 41 },
  11. { "Raz", 41 },
  12. { "Fisnik", 43 },
  13. { "Mikaela", 39 },
  14. { "James", 41 },
  15. { "AMujtaba", 41 },
  16. { "AMujtaba", 41 },
  17. { "James", 41 } };
  18.  
  19. class Solution {
  20. public:
  21. Solution() {
  22. int s1; //Should be 41
  23. std::string s2; //Shoule be "James"
  24.  
  25. s1 = findSize();
  26. s2 = findName();
  27.  
  28. std::cout << s1 << std::endl;
  29. std::cout << s2 << std::endl;
  30. }
  31.  
  32. int findSize() {
  33. // 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.
  34. int n = 0;
  35. int size = 0;
  36.  
  37. for (auto elem : shoeSize) {
  38. if (shoeSize.count(elem.first) > n) {
  39. n = shoeSize.count(elem.first);
  40. size = elem.second;
  41. }
  42. }
  43. return (n < 1) ? -1 : size;
  44. }
  45.  
  46. std::string findName() {
  47. //Find/return the most popular name for the most popular shoe size.
  48. //If there is no uniquely common name, OR if there is no uniquely popular shoe size, return an empty string. Names are case sensitive.
  49. std::string name = "";
  50. int n = 0;
  51.  
  52. for (auto elem : shoeSize) {
  53. if (shoeSize.count(elem.first) > n) {
  54. n = shoeSize.count(elem.first);
  55. name = elem.first;
  56. }
  57. }
  58. return name;
  59. }
  60. };
  61.  
  62. /*
  63. Shoe Sizes
  64. Overview
  65. 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.
  66.  
  67. Make sure to read the entire description before attempting the problem.
  68.  
  69. Task Description
  70. 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.
  71.  
  72. Problem 1): popular_size
  73. 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.
  74.  
  75. Problem 2): popular_name
  76. 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.
  77.  
  78. In the above example, the answer to question 1 would be 41 - and the answer to question 2 would be 'James'.
  79.  
  80. Canvas Description
  81. Canvas Explained
  82.  
  83. API Description
  84. 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.
  85.  
  86. List Length
  87. The number of names and associated shoe sizes available to you for the given level.
  88. Name
  89. The name of a person at a given list index.
  90. Size
  91. The shoe-size of a person at a given list index.
  92. Scoring
  93. 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.
  94.  
  95. 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.
  96. */
  97. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement