PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Implement sampling and subarray algorithms

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of probabilistic sampling and geometric uniformity alongside array algorithm design for contiguous subarray detection, covering competencies in random number transformation, reasoning about distributions, linear-time scanning, and in-place space optimization.

  • medium
  • Google
  • Coding & Algorithms
  • Data Scientist

Implement sampling and subarray algorithms

Company: Google

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

This coding round contained two algorithmic prompts: 1. **Uniform sampling in a 2D square** You are given access to a function `rand01()` that returns independent samples from the continuous uniform distribution `Uniform(0, 1)`. Implement a function that returns a 2D point `(x, y)` sampled uniformly from the square `(-1, 1) × (-1, 1)`. You may call `rand01()` as many times as needed. Briefly explain why your method produces a uniform sample. 2. **Longest increasing contiguous subarray** Given an integer array `nums` of length `n`, find the length of the longest **contiguous** subarray such that every adjacent pair is strictly increasing; that is, for all valid `i` in the subarray, `nums[i] < nums[i+1]`. Aim for `O(n)` time and `O(1)` extra space. If helpful, also describe how to recover the start and end indices of such a subarray.

Quick Answer: This question evaluates understanding of probabilistic sampling and geometric uniformity alongside array algorithm design for contiguous subarray detection, covering competencies in random number transformation, reasoning about distributions, linear-time scanning, and in-place space optimization.

Related Interview Questions

  • Solve Rooms and Top-K Streams - Google (medium)
  • Find Containing Range - Google (medium)
  • Rearrange Tasks With Cooldown - Google (medium)
  • Implement Employee Management and Expression Evaluation - Google (medium)
  • Solve Three Array and Matrix Path Problems - Google (medium)
Google logo
Google
Mar 9, 2025, 12:00 AM
Data Scientist
Technical Screen
Coding & Algorithms
3
0
Loading...

This coding round contained two algorithmic prompts:

  1. Uniform sampling in a 2D square
    You are given access to a function rand01() that returns independent samples from the continuous uniform distribution Uniform(0, 1) . Implement a function that returns a 2D point (x, y) sampled uniformly from the square (-1, 1) × (-1, 1) . You may call rand01() as many times as needed. Briefly explain why your method produces a uniform sample.
  2. Longest increasing contiguous subarray
    Given an integer array nums of length n , find the length of the longest contiguous subarray such that every adjacent pair is strictly increasing; that is, for all valid i in the subarray, nums[i] < nums[i+1] . Aim for O(n) time and O(1) extra space. If helpful, also describe how to recover the start and end indices of such a subarray.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Data Scientist•Google Data Scientist•Google Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.