Other 2010 FR Questions FR other years Be Prepared Home
A-3
Part (a)
  public boolean isLevelTrailSegment(int start, int end)
  {
    int max = markers[start];
    int min = markers[start];

    for (int i = start + 1; i <= end; i++)
    {
      if (markers[i] > max)
        max = markers[i];
      if (markers[i] < min)
        min = markers[i];
    }

    return max - min <= 10;
  } 1
Notes:
  1. Alternative solution:
      public boolean isLevelTrailSegment(int start, int end)
      {
        for (int i = start; i < end; i++)
          for (int j = i+1; j <= end; j++)
            if (Math.abs(markers[i] - markers[j]) > 10)
              return false;
        return true;
      }


Part (b)
  public boolean isDifficult()
  {
    int count = 0;

    for (int i = 0; i < markers.length - 1; i++)
    {
      if (Math.abs(markers[i+1] - markers[i]) >= 30) 1
        count++;
    }

    return count >= 3;
  }
Notes:
  1. Or:
      if (markers[i+1] - markers[i] >= 30 || markers[i] - markers[i+1] >= 30)
    

Other 2010 FR Questions | Back to Contents

Copyright © 2010 by Skylight Publishing
support@skylit.com