Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Reading the contract

โญโญ intermediateโณ 10 min read๐Ÿ“ Lesson 81 of 256

Extract signature, inputs, output, and bound words before writing code.

An AP question is a contract, not a conversation. Every part of it carries obligations:

Write method `int countInRange(int[] data, int lo, int hi)`
Return the number of elements of `data` that are greater than or equal
to `lo` and less than or equal to `hi`.

Before writing a single line, extract the contract's four parts:

  1. Name & signature โ€” countInRange, three parameters, returns int. The signature is given; you may not change it.
  2. Inputs โ€” data (an int[], possibly length 0), lo and hi (int, any order).
  3. Output โ€” a count: an integer โ‰ฅ 0, returned, never printed.
  4. Conditions โ€” "greater than or equal to lo" and "less than or equal to hi": both bounds are inclusive. The words is / or / and / at least decide your operators.

The exam loves three hidden traps inside plain English:

  • inclusive vs exclusive bounds: "from the first through the last" means <=; "between" on the AP exam is stated exactly โ€” obey the words given, never a convention you remember from elsewhere.
  • count vs find: "return the number of..." wants a counter, not the element and not its index.
  • return vs print: an FRQ that asks you to return prints nothing. A solution that prints the answer scores zero for that part.

Train the reading habit: underline the return type, circle every comparative phrase, and list the edge inputs (empty array, single element, all matching, none matching) before you code.