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...


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)<br>Output<br>• For every query of type MaxScore() and GetScore(), print the output of that query on separate line<br>Constraints<br>1 <= Q <= 2 * 105<br>-108 <= a <= 108<br>length of string s <= 10<br>Example<br>Input<br>10<br>A abc 10<br>A pqr 5<br>M<br>А ааа 10<br>G pqr<br>M<br>D aaa<br>M<br>G abc<br>G aaa<br>Output<br>abc 10<br>aaа 10<br>abc 10<br>10<br>

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

Extracted 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
Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here