Goal: Write an HTTP service which accepts an array of strings and returns the se
ID: 3735452 • Letter: G
Question
Goal:
Write an HTTP service which accepts an array of strings and returns the sets of strings which collide in the hash table in the order they appeared in the input list.
Problem:
Receive as input an array of strings.
Return the set of strings which collide in the hash table in the order they appear in the input list.
The hash algorithm should be implemented as the sum of the ASCII values of the lower-cased letters. For example, “Bob”, “bob”, and “obb” all hash to the same number.
Example input:
{ "inList" : [ "Bob", "boj", "obb", "job", "BOB", "foo" ] }
Example output:
{"outList": [ [ "Bob", "obb", "BOB" ] , [ "boj", "job" ] ] }
Do not output strings which do not collide, such as “foo” in the example above. If the table has no collisions, return the empty array. { "outList" : [ ] }
Erroneous input (e.g. malformed JSON) should be handled gracefully with appropriate error messages.
Can someone help me out? In Java preferably.
Explanation / Answer
I think you need help in android based or java based technology. I am giving you with the functions that will help you with this.
THIS IS THE BASIC ALGORITHM I.E CALCULATE THE SUM OF ALL ASCII IN LOWER CASE.
THIS IS THE FUNCTION WHERE YOU CAN SIMPLY HAVE A SERVICE ALL FOR INPUT JSON AND THEN MANIPULATE IT TO GET YOUR OUTPUT JSON
THIS IS A SAMPLE FUNCTION AS HOW TO MAKE A CALL :HTTPSERVICE
private static String USERID="ADAM";
private static String PASSWORD="123";
public static String getJSON() throws UnsupportedEncodingException {
String text = "Error Occured!! Try again..";
try{
String data = URLEncoder.encode("apiLogin", "UTF-8") + "=" + URLEncoder.encode(USERID, "UTF-8");
data += "&" + URLEncoder.encode("apiPass", "UTF-8") + "=" + URLEncoder.encode(PASSWORD, "UTF-8");
BufferedReader reader = null;
// Send data
try {
URL url = new URL("http://www.example.com/getJSON");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + " ");
}
text = sb.toString();
} catch (Exception e) {
} finally {
try {
reader.close();
} catch (Exception e) {
}
}
}catch (Exception e){
}
return text;
}
SAMPLE INPUT:{ "inList" : [ "Bob", "boj", "obb", "job", "BOB", "foo" ] }
SAMPLE OUTPUT:{"outList": [ [ "Bob", "obb", "BOB" ] , [ "boj", "job" ] ] }
**************************************************************************************************************************
IF YOU HAVE ANY DOUBTS KINDLY COMMENT. ALL THE BEST. HAVE A GOOD DAY
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.