TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

SHAKY

Problem statement, definition, constraints, and public examples.

Problem Statement

TopCoder has made up a term to describe a certain type of number.  We call it a
"shaky" number.  You can determine if a number is shaky according to the
following rules:
(1) starting from the left-most digit and moving right, a pattern must be
followed of "greater than", "less than", "greater than", "less than", etc. For
example, 465768 is considered shaky because
6 is greater than 4,
5 is less than 6
7 is greater then 5
6 is less than 7
8 is greater than 6
(2) any single digit number IS considered shaky.
(3) The first comparison may be "greater than" or "less than", and alternate
after that. It does not necessarily need to end with a "greater than" or "less
than".

Create a class Shaky that contains the following method signature:

public boolean isShaky(int);

This method will accept a valid int value that is greater than zero and
determine if the 
number is shaky, returning true for shaky and false for not shaky.

EXAMPLES:

5252 - should return true
2525 - should return true
25 - should return true
52 - should return true
8 - should return true

33 - should return false
521 - should return false
23234 - should return false

Definition

Class:
SHAKY
Method:
isShaky
Parameters:
int
Returns:
boolean
Method signature:
boolean isShaky(int param0)
(be sure your method is public)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems