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 */
}
}
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="">=>
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