一道电面题,分享下, 这个题应该用哪几个data structure?# JobHunting - 待字闺中
d*i
1 楼
given input as an array of strings.
Such as: {"apple Orange", "ORANGE apple", "APPLe oRange", "HI There", "THERE
hI"};
return an array of strings. in the above case, will return "APPLe, oRange",
""THERE hI".
Here are the rules:
1. two strings are the same when words matches(case insensitive) and order
doesn't matter, so "apple Orange" == "APPLe oRange" == "ORANGE apple".
2. if multiple identical strings exist, only return the one that occurs at
the last location, so "APPLe oRange" and "THERE hI" will in the result.
3. the relative order cannot be changed, so we cannot have result as "THERE
hI", "APPLe oRange".
Any idea on what data structure is the best for this question?
Such as: {"apple Orange", "ORANGE apple", "APPLe oRange", "HI There", "THERE
hI"};
return an array of strings. in the above case, will return "APPLe, oRange",
""THERE hI".
Here are the rules:
1. two strings are the same when words matches(case insensitive) and order
doesn't matter, so "apple Orange" == "APPLe oRange" == "ORANGE apple".
2. if multiple identical strings exist, only return the one that occurs at
the last location, so "APPLe oRange" and "THERE hI" will in the result.
3. the relative order cannot be changed, so we cannot have result as "THERE
hI", "APPLe oRange".
Any idea on what data structure is the best for this question?