Find Values Repeated in Three Consecutive Log Rows

Quick Overview

Find distinct values occupying at least three consecutive log rows, preserving varchar values and repeated-run deduplication.

Find Values Repeated in Three Consecutive Log Rows

Company: Google

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

### Problem Report each num that appears in at least three consecutive Logs rows in id order. The source id is an auto-increment key starting at 1. Name the output column ConsecutiveNums and return each qualifying value once, in any result row order. ### Tables Table: `Logs` ```text +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | num | varchar | +-------------+---------+ In SQL, id is the primary key for this table. id is an autoincrement column starting from 1. ``` ### Example ```text Logs (id,num): (1,4), (2,4), (3,4), (4,4), (5,7), (6,7) Output (ConsecutiveNums): (4) ``` ### What a Strong Answer Covers - Use the log order when deciding which rows are consecutive. - Return each qualifying value once, even when several runs qualify. - Preserve the original value type and handle logs with no qualifying rows. ### Follow-up Questions - How would your answer change if a missing ID also broke a run? - What would you return if the interviewer asked for the length of each qualifying run?

Overview: Find distinct values occupying at least three consecutive log rows, preserving varchar values and repeated-run deduplication.

Google logo
Google
Oct 4, 2026
mediumSoftware EngineerOtherData Manipulation (SQL/Python)
0
0

Problem

Report each num that appears in at least three consecutive Logs rows in id order. The source id is an auto-increment key starting at 1. Name the output column ConsecutiveNums and return each qualifying value once, in any result row order.

Tables

Table: Logs

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| id          | int     |
| num         | varchar |
+-------------+---------+
In SQL, id is the primary key for this table.
id is an autoincrement column starting from 1.

Example

Logs (id,num): (1,4), (2,4), (3,4), (4,4), (5,7), (6,7)
Output (ConsecutiveNums): (4)

What a Strong Answer Covers Guidance

  • Use the log order when deciding which rows are consecutive.
  • Return each qualifying value once, even when several runs qualify.
  • Preserve the original value type and handle logs with no qualifying rows.

Follow-up Questions Guidance

  • How would your answer change if a missing ID also broke a run?
  • What would you return if the interviewer asked for the length of each qualifying run?