Create a data structure to support the following operations. (s is a string consisting of only lowercase English alphabets and a is an integer) • Assign(s, a) : Assign string s a score of a (Update the score of s to a if already assigned something else) • Delete(s): Delete s and its score, if it exists • MaxScore() : Print the lexicographically smallest string with the maximum score followed by the maximum score, separated by a space. You can assume that whenever MaxScore() is queried, there is at least one string present. • GetScore(s) : Print the score assigned to the string s, if it exists, print 0 otherwise. Input First line of contains N, the number of queries in the test case, followed by N lines describing 1 query in each line. Each query line starts with a single capital letter describing the type of query followed by the arguments. • A' followed by string s and integer a => Assign(s, a) • 'D' followed by string s => Delete(s) 'M' => MaxScore() • 'G' followed by s => GetScore(s) Output • For every query of type MaxScore() and GetScore(), print the output of that query on separate line

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please give a full detailed optimized solution in Java 8 for the given problem, use the example code provided as well. Please provide comments and screenshots of code and output. Also, add the time/space complexity and the reason for it.
Java 8 Code Example:
import java.io.*;

import java.util.*;

import java.text.*;

import java.math.*;

import java.util.regex.*;

public class Solution {

    public static void main(String args[] ) throws Exception {

        /* Enter your code here. Read input from STDIN. Print output to STDOUT */

    }

}

• 'Gʻ followed bys => GetScore(s)
Output
• For every query of type MaxScore() and GetScore(), print the output of that query on separate line
Constraints
1 <= Q <= 2 * 105
-108 <= a <= 108
length of string s <= 10
Example
Input
10
A abc 10
A pqr 5
M
А ааа 10
G pqr
M
D aaa
M
G abc
G aaa
Output
abc 10
aaа 10
abc 10
10
Transcribed Image Text:• 'Gʻ followed bys => GetScore(s) Output • For every query of type MaxScore() and GetScore(), print the output of that query on separate line Constraints 1 <= Q <= 2 * 105 -108 <= a <= 108 length of string s <= 10 Example Input 10 A abc 10 A pqr 5 M А ааа 10 G pqr M D aaa M G abc G aaa Output abc 10 aaа 10 abc 10 10
2. Queries
Create a data structure to support the following operations.
(s is a string consisting of only lowercase English alphabets and a is an integer)
• Assign(s, a) : Assign string s a score of a (Update the score of s to a if already assigned something else)
Delete(s) : Delete s and its score, if it exists
• MaxScore() : Print the lexicographically smallest string with the maximum score followed by the
maximum score, separated by a space. You can assume that whenever MaxScore() is queried, there is at
least one string present.
• GetScore(s) : Print the score assigned to the string s, if it exists, print 0 otherwise.
Input
First line of contains N, the number of queries in the test case, followed by N lines describing 1 query
in each line.
Each query line starts with a single capital letter describing the type of query followed by the
arguments.
• 'A' followed by string s and integer a => Assign(s, a)
• 'D' followed by string s => Delete(s)
• 'M' => MaxScore()
• 'G' followed bys => GetScore(s)
Output
• For every query of type MaxScore() and GetScore(), print the output of that query on separate line
Transcribed Image Text:2. Queries Create a data structure to support the following operations. (s is a string consisting of only lowercase English alphabets and a is an integer) • Assign(s, a) : Assign string s a score of a (Update the score of s to a if already assigned something else) Delete(s) : Delete s and its score, if it exists • MaxScore() : Print the lexicographically smallest string with the maximum score followed by the maximum score, separated by a space. You can assume that whenever MaxScore() is queried, there is at least one string present. • GetScore(s) : Print the score assigned to the string s, if it exists, print 0 otherwise. Input First line of contains N, the number of queries in the test case, followed by N lines describing 1 query in each line. Each query line starts with a single capital letter describing the type of query followed by the arguments. • 'A' followed by string s and integer a => Assign(s, a) • 'D' followed by string s => Delete(s) • 'M' => MaxScore() • 'G' followed bys => GetScore(s) Output • For every query of type MaxScore() and GetScore(), print the output of that query on separate line
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Top down approach design
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education