TopCoder problem "CarParking" used in TCHS SRM 22 (Division I Level Two)



Problem Statement

    The town John lives in consists of a large number of streets numbered 1 to streets, inclusive. He insists on parking his car only on street numbers that are palindromic (i.e., they read the same forward and backward). He is currently located at street number now. Return the closest street where he can park his car. If there are multiple solutions, return the smallest among them.
 

Definition

    
Class:CarParking
Method:closestShed
Parameters:int, int
Returns:int
Method signature:int closestShed(int now, int streets)
(be sure your method is public)
    
 

Notes

-Leading zeroes shouldn't be considered. So you can't interpret "10" as "010" and consider it palindromic.
 

Constraints

-streets will be between 1 and 2147483647, inclusive.
-now will be between 1 and streets, inclusive.
 

Examples

0)
    
19
22
Returns: 22
22 is the closest palindromic street.
1)
    
19
21
Returns: 11
Now there is one less street. So the next nearby palindrome is 11.
2)
    
1234567
12345678
Returns: 1234321
3)
    
9999
99999999
Returns: 9999

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10074&pm=7258

Writer:

myprasanna

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Brute Force, Search, Simulation