gudii9
asked on
pairs challenge
Hi,
I am working on below challenge.
http://codingbat.com/prob/p126332
Not clear on the description.
please advise
I am working on below challenge.
http://codingbat.com/prob/p126332
Given an array of non-empty strings, create and return a Map<String, String> as follows: for each string add its first character as a key with its last character as the value.
pairs(["code", "bug"]) → {"b": "g", "c": "e"}
pairs(["man", "moon", "main"]) → {"m": "n"}
pairs(["man", "moon", "good", "night"]) → {"g": "d", "n": "t", "m": "n"}
Not clear on the description.
please advise
ASKER
no duplicates?
ASKER
pairs(["man", "moon", "main"]) → {"m": "n"}
above has only one m and n not 3 times for man, moon, main
above has only one m and n not 3 times for man, moon, main
ASKER
public Map < String, String > pairs(String[] strings) {
Map < String, String > map = new HashMap();
for (int i = 0; i < strings.length; i++) {
String test = strings[i];
String first = String.valueOf(test.charAt(0));
String last = String.valueOf(test.charAt(test.length() - 1));
map.put(first, last);
// map.put("1","last");
}
return map;
}
looks like map removed all duplicate keys by itself/
above passed all tests. any improvement or alternate approaches?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> "Not clear on the description.
> please advise"
Unless you tell us which parts of the description you are not clear on, it's a bit hard for us to know how to advise you. Do you expect us to rewrite the entire description and hope that you understand our version?
So, instead of making this a guessing game for us, please be specific. We're expert programmers, not expert mind readers.
Thanks.
tel2