# [LintCode] Segment Tree Query

### Question

For an integer array (index from 0 to n-1, where n is the size of this array), in the corresponding SegmentTree, each node stores an extra attribute max to denote the maximum number in the interval of the array (index from start to end).

Design a query method with three parameters root, start and end, find the maximum number in the interval [start, end] by the given root of segment tree.

### Solution

Slightly difficult as we need to keep in mind the following:

1. what’s the return condition? (start and end is large enough to cover the entire range)

2. how to handle overlapping case? (find min-point first and then analyse case by case)

### Code

``````/**
* Definition of SegmentTreeNode:
* public class SegmentTreeNode {
*     public int start, end, max;
*     public SegmentTreeNode left, right;
*     public SegmentTreeNode(int start, int end, int max) {
*         this.start = start;
*         this.end = end;
*         this.max = max
*         this.left = this.right = null;
*     }
* }
*/
public class Solution {
/**
*@param root, start, end: The root of segment tree and
*                         an segment / interval
*@return: The maximum number in the interval [start, end]
*/
public int query(SegmentTreeNode root, int start, int end) {