Problem Statement
You are given a String[], items, each element of which represents a single auction item and is formatted as "<title> <timeLeft>" (quotes for clarity only). <title> contains the title of the auction and consists of only lowercase letters ('a'-'z') and spaces (but no leading or trailing spaces). <timeLeft> represents the time remaining before the auction ends, and is formatted as "H:MM" (quotes for clarity only), where H is the number of hours (an integer between 0 and 23, inclusive, with no extra leading zeros) and MM represents the number of minutes (an integer between 00 and 59, inclusive, with exactly 2 digits).
Given a search term consisting entirely of lowercase letters ('a'-'z'), return all the items whose titles contain the search term as a substring, sorted in ascending order by remaining time. The constraints will guarantee that no two items will have the same amount of time remaining. The return value is a String[] whose elements are formatted exactly the same as items.
Definition
- Class:
- AuctionSearch
- Method:
- search
- Parameters:
- String[], String
- Returns:
- String[]
- Method signature:
- String[] search(String[] items, String searchTerm)
- (be sure your method is public)
Constraints
- items will contain between 1 and 50 elements, inclusive.
- Each element of items will be formatted as described in the statement.
- Each <title> will be between 1 and 30 characters in length, inclusive.
- No two elements of items will have the same <timeLeft>
- searchTerm will contain between 1 and 30 characters, inclusive.
- searchTerm will contain only lowercase letters ('a'-'z').
Examples
{"autographed photograph 10:15", "toaster oven 23:12", "photograph 0:20", "photo 9:59"}"photo"
Returns: {"photograph 0:20", "photo 9:59", "autographed photograph 10:15" }The three titles that contain "photo" as a substring are: "autographed photograph", "photograph", and "photo".{"not what you want 0:01"}"stuff"
Returns: { }An empty String[] is returned when there are no matches.{"same item 0:00", "same item 0:02", "same item 0:01"}"same"
Returns: {"same item 0:00", "same item 0:01", "same item 0:02" }Multiple items can have the same title.