PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Coinbase

Implement local maxima, bagging, and k-means

Last updated: Mar 29, 2026

Quick Overview

This set of tasks evaluates algorithmic problem-solving and implementation skills across array processing (local maxima), ensemble methods (bagging classifier), and clustering (k-means), testing competencies in data structures, statistical resampling, numerical computation, and scalable code in the Coding & Algorithms and Machine Learning domains.

  • hard
  • Coinbase
  • Coding & Algorithms
  • Machine Learning Engineer

Implement local maxima, bagging, and k-means

Company: Coinbase

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Take-home Project

You have 70 minutes for three programming tasks. ## Task 1 — Find local maxima Given an integer array `a` of length `n` (`1 <= n <= 2e5`), return all indices `i` that are **local maxima**. Definition: - For `0 < i < n-1`: `a[i]` is a local maximum if `a[i] > a[i-1]` **and** `a[i] > a[i+1]`. - For endpoints: `i = 0` is a local maximum if `n==1` or `a[0] > a[1]`; `i = n-1` is a local maximum if `a[n-1] > a[n-2]`. Output the indices in increasing order. ## Task 2 — Implement a bagging classifier Implement a `BaggingClassifier` that trains `M` base classifiers on bootstrap samples and predicts by majority vote. You are given a `BaseClassifier` object with: - `fit(X, y)` - `predict(X)` which returns a label for each row of `X` Your `BaggingClassifier` should support: - constructor parameters: `n_estimators=M`, `sample_size` (default = `len(X)`), `random_seed` - `fit(X, y)` that trains `M` independent base models on bootstrap samples (sample with replacement) - `predict(X)` that returns the majority-vote label per example; if there is a tie, return the smallest label. Constraints: `N = len(X) <= 2e5`, `M <= 200`. ## Task 3 — Implement k-means clustering Implement k-means clustering given: - `X`: `N x D` array of floats - `k`: number of clusters - `dist(p, q)`: provided distance function between two points - `max_iter` (e.g., 100) Requirements: 1. Initialize centroids using the first `k` points of `X` (deterministic). 2. Repeat until convergence or `max_iter`: - Assign each point to the nearest centroid (break ties by choosing the smallest centroid index). - Recompute each centroid as the mean of its assigned points. - If a cluster becomes empty, keep its centroid unchanged. Return final centroids and the cluster assignment for each point. (You may assume `1 <= k <= N`, `D <= 50`.)

Quick Answer: This set of tasks evaluates algorithmic problem-solving and implementation skills across array processing (local maxima), ensemble methods (bagging classifier), and clustering (k-means), testing competencies in data structures, statistical resampling, numerical computation, and scalable code in the Coding & Algorithms and Machine Learning domains.

Related Interview Questions

  • Implement an In-Memory Database - Coinbase (hard)
  • Implement a Coin-Constrained Jump Strategy - Coinbase (hard)
  • Implement Game Physics and Block Mining - Coinbase (hard)
  • Compute Total Manual Distance - Coinbase (medium)
  • Implement a Flappy Bird Jump Agent - Coinbase
Coinbase logo
Coinbase
Feb 1, 2026, 12:00 AM
Machine Learning Engineer
Take-home Project
Coding & Algorithms
9
0
Loading...

You have 70 minutes for three programming tasks.

Task 1 — Find local maxima

Given an integer array a of length n (1 <= n <= 2e5), return all indices i that are local maxima.

Definition:

  • For 0 < i < n-1 : a[i] is a local maximum if a[i] > a[i-1] and a[i] > a[i+1] .
  • For endpoints: i = 0 is a local maximum if n==1 or a[0] > a[1] ; i = n-1 is a local maximum if a[n-1] > a[n-2] .

Output the indices in increasing order.

Task 2 — Implement a bagging classifier

Implement a BaggingClassifier that trains M base classifiers on bootstrap samples and predicts by majority vote.

You are given a BaseClassifier object with:

  • fit(X, y)
  • predict(X) which returns a label for each row of X

Your BaggingClassifier should support:

  • constructor parameters: n_estimators=M , sample_size (default = len(X) ), random_seed
  • fit(X, y) that trains M independent base models on bootstrap samples (sample with replacement)
  • predict(X) that returns the majority-vote label per example; if there is a tie, return the smallest label.

Constraints: N = len(X) <= 2e5, M <= 200.

Task 3 — Implement k-means clustering

Implement k-means clustering given:

  • X : N x D array of floats
  • k : number of clusters
  • dist(p, q) : provided distance function between two points
  • max_iter (e.g., 100)

Requirements:

  1. Initialize centroids using the first k points of X (deterministic).
  2. Repeat until convergence or max_iter :
    • Assign each point to the nearest centroid (break ties by choosing the smallest centroid index).
    • Recompute each centroid as the mean of its assigned points.
    • If a cluster becomes empty, keep its centroid unchanged.

Return final centroids and the cluster assignment for each point.

(You may assume 1 <= k <= N, D <= 50.)

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Coinbase•More Machine Learning Engineer•Coinbase Machine Learning Engineer•Coinbase Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.