MapSum Pair Implementation
Create a data structure named 'MapSum' with the ability to perform two operations and a constructor.
Explanation:
Implement the following:
MapSum()
: Initializes the MapSum.insert(KEY, VAL)
: Inserts a key-value pair into the MapSum. If the key already exists, update its value.sum(PREFIX)
: Calculates the sum of all values for which the keys have the specified prefix.
Input:
The first line will contain an integer 'T' representing the number of test cases.
For each test case, the first line contains an integer 'N', indicating the number of operations to perform.
Each of the next 'N' lines contains either a function call to 'insert' with a 'key-value' pair or 'sum' with a 'PREFIX'.
Output:
The output for each test case will be executed based on the function operations described above, printed on a separate line.
Example:
Suppose you have two test cases, and for the first test case:
N = 3
Operations:
insert("apple", 3)
sum("ap") -> outputs 3
insert("app", 2)
sum("ap") -> outputs 5
Constraints:
1 <= T <= 50
2 <= N <= 10000
1 <= |KEY|, |PREFIX| <= 50
1 <= VAL <= 1000
The |KEY| and |PREFIX| represent the lengths of the string key and prefix, while VAL denotes the value associated with a key.
Time limit: 1 second
Note:
It is not necessary to handle input or output explicitly; focus on implementing the required functions.

AnswerBot
1y
The question asks to implement a data structure called 'MapSum' with functions to initialize, insert key-value pairs, and find the sum of values with a given prefix.
Implement a class called 'MapSum' w...read more
Help your peers!
Add answer anonymously...
GlobalLogic Senior Software Engineer interview questions & answers
A Senior Software Engineer was asked 2mo agoQ. What are fact and dimension tables?
A Senior Software Engineer was asked 2mo agoQ. What optimization techniques can be used in Databricks?
A Senior Software Engineer was asked 4mo agoQ. Write a program to check if a given string is a palindrome.
Popular interview questions of Senior Software Engineer
A Senior Software Engineer was asked 2mo agoQ1. What are fact and dimension tables?
A Senior Software Engineer was asked 2mo agoQ2. What optimization techniques can be used in Databricks?
A Senior Software Engineer was asked 5mo agoQ3. Write a program to check if a given string is a palindrome.
>
GlobalLogic Senior Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

