code: Long fit(long start, long duration, int n) {
          OUTER:
          while (true) {
              long t = start;
              // check if 'start' satisfies the two conditions by moving t across [start,start+duration)
              while ((t-start)<duration) {
                  if (at(t)>n) {
                      // value too big. what's the next t that's worth trying?
                      Long nxt = next(t);
                      if (nxt==null)  return null;
                      start = nxt;
                      continue OUTER;
                  } else {
                      Long nxt = next(t);
                      if (nxt==null) t = Long.MAX_VALUE;
                      else           t = nxt;
                  }
              }
              // q(t) looks good at the entire [start,start+duration)
              return start;
          }
      }
docs: Finds a "valley" in this timeline that fits the given duration.
  <p>
  More formally, find smallest x that:
  <ul>
  <li>x >= start
  <li>q(t) <= n for all t \in [x,x+duration)
  </ul>
  
  @return null
  if no such x was found.