This multi-part problem evaluates skills in random sampling and geometric probability for uniform 2D sampling, algorithmic array processing for finding the longest strictly increasing contiguous subarray, and statistical approximation and interpolation from bucketed histogram counts to estimate percentiles.
You will solve three independent coding tasks.
You are given access to a function rand01() that returns an i.i.d. sample from a continuous Uniform(0, 1) distribution.
Write a function samplePoint() that returns a 2D point (x, y) that is uniformly distributed over the square:
Constraints/requirements:
rand01()
as many times as needed.
Given an integer array nums, compute the length of the longest contiguous subarray that is strictly increasing.
Example:
nums = [1, 3, 5, 4, 7]
→ answer is
3
(subarray
[1, 3, 5]
)
Clarifications:
nums[i] < nums[i+1]
.
You have search queries aggregated into K buckets (a histogram). Each bucket i has:
left_i
: left boundary (inclusive)
right_i
: right boundary (exclusive, unless it is the last bucket)
count_i
: number of observations in that bucket
You do not know the individual values inside buckets—only bucket boundaries and counts.
Write a function to return an approximation of the p-th percentile (e.g., p=0.90 for 90th percentile).
Required behavior/assumptions (state clearly in your answer):
N = sum(count_i)
.
Output: