private int lastOccurence(int[] nums, int target) {
        int low = 0;
        int high = nums.length - 1;
        while (low <= high) {
            int mid = low + (high - low)/2;
            if (nums[mid] == target && (mid == nums.length - 1 || nums[mid + 1] > target)) {
                return mid;
            } else if (nums[mid] <= target) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
        return -1;
    }
Date 07/31/2016
@author Tushar Roy

Given a sorted array of integers, find the starting and ending position of a given target value.

Time complexity O(logn)
Space complexity O(1)

https://leetcode.com/problems/search-for-a-range/
src/com/interview/binarysearch/SearchForRange.java