mergegroupby

The full problem statement is available to Pro members.

preloaded fixtures

import pandas as pd
import numpy as np

requests = pd.DataFrame({
    "org": ["Northwind", "Northwind", "Playform", "Serene", "Hooli", "Hooli", "Globex", "Globex"],
    "model": ["gpt-flash", "gpt-pro", "gpt-flash", "gpt-flash", "gpt-pro", "gpt-flash", "gpt-pro", "gpt-flash"],
    "input_tokens": [1200, 5000, 300, 150, 12000, 800, 7000, 1100],
    "output_tokens": [400, 1800, 90, 40, 4200, 200, 2500, 350],
    "latency_ms": [820, 3200, 450, 510, 5100, 530, 3900, 700],
    "status": ["ok", "ok", "ok", "error", "ok", "ok", "ok", "rate_limited"],
})

pricing = pd.DataFrame({
    "model": ["gpt-mini", "gpt-flash", "gpt-pro"],
    "input_per_1k": [0.0002, 0.0010, 0.0100],
    "output_per_1k": [0.0008, 0.0030, 0.0300],
})

Guest mode · solve history stays on this device; code isn’t saved. Sign in to save future work

Pro problem

“Spend by organisation”

This is one of the real interview questions in Pro. Try Pro free for 7 days to unlock it and everything below:

  • 293 interview-grade problems across SQL, Python & pandas
  • 104+ real-world SQL problems: SaaS retention, fintech ledgers, supply chain, recursive CTEs
  • 18 company interview packs (Amazon, Meta, Google, Uber and more)
  • AI "explain my mistake" tutor and mock interviews
  • Use QueryLab inside Claude, Cursor & other AI assistants

// built for real interview rounds

Practice the patterns 18 top companies test

329 problems · 36 free forever · 293 unlocked with Pro

Card required. Then $12/month. Cancel before your trial ends and you pay nothing.

or keep practicing free problems →

Secure checkout by Paddle · instant access · cancel anytime from your account