# Trim Endpoints Right

> Trailing whitespace. Clean it up.

Canonical URL: <https://datadriven.io/problems/trim_endpoints_right>

Domain: SQL · Difficulty: easy · Seniority: L3

## Problem

A data quality check flagged trailing whitespace in endpoint names. Clean it up by returning each endpoint with trailing spaces removed, by call ID.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests knowledge of string cleaning functions. Interviewers check whether you know `RTRIM` and can apply it in a data quality context.

---

### Break down the requirements

#### Step 1: Apply RTRIM to strip trailing spaces

`RTRIM(endpoint)` removes trailing whitespace characters from each endpoint value.

#### Step 2: Return by call ID

Select `call_id` and the cleaned endpoint, implicitly ordered by call_id or as stored.

---

### The solution

**RTRIM for trailing whitespace cleanup**

```sql
SELECT call_id, RTRIM(endpoint) AS endpoint
FROM api_calls
```

> **Cost Analysis**
>
> Full scan of 100M rows. RTRIM is an O(n) string operation per row where n is the string length. For short endpoint names (~90 characters), this is negligible.

> **Interviewers Watch For**
>
> Candidates who use `TRIM` (which removes both sides) instead of `RTRIM` (right only). The prompt specifically says trailing whitespace.

> **Common Pitfall**
>
> Using `REPLACE(endpoint, ' ', ")` which removes ALL spaces, including legitimate internal spaces in endpoint paths like '/api/v2/user profile'.

---

## Common follow-up questions

- What if you needed to remove trailing tabs and newlines as well? _(Some engines' RTRIM only handles spaces; you may need RTRIM with a character set or REGEXP_REPLACE.)_
- How would you find which rows actually had trailing whitespace? _(Compare `endpoint != RTRIM(endpoint)` to identify affected rows.)_
- Should you update the data in place or create a view? _(Tests understanding of data mutation vs. transformation-on-read patterns.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/trim_endpoints_right)
- [SQL Interview Questions](https://datadriven.io/sql-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.