subject

You've created a new programming language, and now you've decided to add hashmap support to it. Actually you are quite disappointed that in common programming languages it's impossible to add a number to all hashmap keys, or all its values. So you've decided to take matters into your own hands and implement your own hashmap in your new language that has the following operations: insert x y - insert an object with key x and value y.
get x - return the value of an object with key x.
addToKey x - add x to all keys in map.
addToValue y - add y to all values in map.
To test out your new hashmap, you have a list of queries in the form of two arrays: queryTypes contains the names of the methods to be called (eg: insert, get, etc), and queries contains the arguments for those methods (the x and y values).
Your task is to implement this hashmap, apply the given queries, and to find the sum of all the results for get operations.
Example
For queryType = ["insert", "insert", "addToValue", "addToKey", "get"] and query = [[1, 2], [2, 3], [2], [1], [3]], the output should be hashMap(queryType, query) = 5.
The hashmap looks like this after each query:
1 query: {1: 2}
2 query: {1: 2, 2: 3}
3 query: {1: 4, 2: 5}
4 query: {2: 4, 3: 5}
5 query: answer is 5
The result of the last get query for 3 is 5 in the resulting hashmap.
For queryType = ["insert", "addToValue", "get", "insert", "addToKey", "addToValue", "get"] and query = [[1, 2], [2], [1], [2, 3], [1], [-1], [3]], the output should be hashMap(queryType, query) = 6.
The hashmap looks like this after each query:
1 query: {1: 2}
2 query: {1: 4}
3 query: answer is 4
4 query: {1: 4, 2: 3}
5 query: {2: 4, 3: 3}
6 query: {2: 3, 3: 2}
7 query: answer is 2
The sum of the results for all the get queries is equal to 4 + 2 = 6.
Input/Output
[execution time limit] 4 seconds (py3)
[input] array. string queryType
Array of query types. It is guaranteed that each queryType[i] is either "addToKey", "addToValue", "get", or "insert".
Guaranteed constraints:
1 ≤ queryType. length ≤ 105.
[input] array. array. integer query
Array of queries, where each query is represented either by two numbers for insert query or by one number for other queries. It is guaranteed that during all queries all keys and values are in the range [-109, 109].
Guaranteed constraints:
query. length = queryType. length,
1 ≤ query[i].length ≤ 2.
[output] integer64
The sum of the results for all get queries.
[Python3] Syntax Tips
# Prints help message to the console
# Returns a string
def helloWorld(name):
print("This prints to the console when you Run Tests")
return "Hello, " + name

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 09:50
What is a rush associated with alcohol?
Answers: 1
question
Computers and Technology, 22.06.2019 20:30
In this lab, you complete a prewritten c program that calculates an employee’s productivity bonus and prints the employee’s name and bonus. bonuses are calculated based on an employee’s productivity score as shown below. a productivity score is calculated by first dividing an employee’s transactions dollar value by the number of transactions and then dividing the result by the number of shifts worked.
Answers: 3
question
Computers and Technology, 23.06.2019 01:20
Me with this program in c++ ! computers represent color by combining sub-colors red, green, and blue (rgb). each sub-color's value can range from 0 to 255. thus (255, 0, 0) is bright red. (130, 0, 130) is a medium purple. (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray. (130, 50, 130) is a faded purple, due to the (50, 50, 50) gray part. (in other word, equal amounts of red, green, blue yield gray).given values for red, green, and blue, remove the gray part. ex: if the input is 130 50 130, the output is: 80 0 80. thus, find the smallest value, and then subtract it from all three values, thus removing the gray.
Answers: 3
question
Computers and Technology, 23.06.2019 02:00
Read this excerpt from helen keller’s autobiography, the story of my life. have you ever been at sea in a dense fog, when it seemed as if a tangible white darkness shut you in, and the great ship, tense and anxious, groped her way toward the shore with plummet and sounding-line, and you waited with beating heart for something to happen? i was like that ship before my education began, only i was without compass or sounding-line, and had no way of knowing how near the harbour was. "light! give me light! " was the wordless cry of my soul, and the light of love shone on me in that very hour. . the morning after my teacher came she led me into her room and gave me a doll. the little blind children at the perkins institution had sent it and laura bridgman had dressed it; but i did not know this until afterward. when i had played with it a little while, miss sullivan slowly spelled into my hand the word "d-o-l-l." i was at once interested in this finger play and tried to imitate it. when i finally succeeded in making the letters correctly i was flushed with childish pleasure and pride. running downstairs to my mother i held up my hand and made the letters for doll. i did not know that i was spelling a word or even that words existed; i was simply making my fingers go in monkey-like imitation. in the days that followed i learned to spell in this uncomprehending way a great many words, among them pin, hat, cup and a few verbs like sit, stand and walk. based on this excerpt, which words best describe helen keller?
Answers: 2
You know the right answer?
You've created a new programming language, and now you've decided to add hashmap support to it. Actu...
Questions
question
Mathematics, 11.09.2019 22:30
Questions on the website: 13722360