Problem Statement

You are given a String line containing a list of integers, each separated by one or more spaces. Given an int givenNumber, return the smallest int in line that is strictly greater than givenNumber. Return -1 if there is no such number in line.

Definition

 Class: NumbersLine Method: getLeast Parameters: String, int Returns: int Method signature: int getLeast(String line, int givenNumber) (be sure your method is public)

Notes

-line may contain leading and/or trailing spaces.

Constraints

-line will contain between 1 and 50 characters, inclusive.
-Each character in line will be either a digit ('0'-'9') or a space (' ').
-line will contain a list of integers, separated by one or more spaces, where each integer is between 1 and 1000, inclusive, with no leading zeros.
-line will contain at least one integer.
-givenNumber will be between 1 and 1000, inclusive.

Examples

0)

 `"1 2 3 4 5"` `2`
`Returns: 3`
 3 is the smallest number strictly greater than 2.
1)

 `"120 450 780"` `1000`
`Returns: -1`
 There are no numbers strictly greater than 1000.
2)

 `" 45 253 645 400 676 567 "` `1`
`Returns: 45`
3)

 `" 45 253 645 400 676 567 "` `400`
`Returns: 567`
4)

 `" 568 769 436 432 457 563 567 311 34 3 2 9"` `460`
`Returns: 563`

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6729

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10067&pm=6729

Vedensky

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Brute Force, String Parsing