Detect identical snowflakes under rotation and reflection

Quick Overview

Decide whether any two six-arm snowflakes in a list of up to 100,000 match when one may be rotated or mirrored. Tests reasoning about equivalence under rotation and reflection and detecting duplicates at scale without comparing every pair.

Detect identical snowflakes under rotation and reflection

Company: Patreon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

You are given a list of snowflakes `snowflakes`, where each snowflake is an array of 6 integers describing its arms in order. Determine whether any two snowflakes are identical. Two snowflakes are identical if one can be obtained from the other by: - a rotation, which is a cyclic shift of the 6 arms, or - a mirror reflection, which reverses the arms and then applies any cyclic shift. Return `True` if any such pair exists in the list, otherwise return `False`. ### Function Signature ```python def has_identical_snowflakes(snowflakes: list[list[int]]) -> bool: ``` ### Rules - A pair means two different positions in the list. Two entries with exactly the same values are identical (a shift by zero), so they count as a pair. - A list with a single snowflake has no pair, so the answer is `False`. ### Constraints - `1 <= len(snowflakes) <= 10^5` - `len(snowflakes[i]) == 6` - `0 <= snowflakes[i][j] <= 10^9` ### Examples ```text Input: snowflakes = [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 7], [3, 4, 5, 6, 1, 2]] Output: True ``` The snowflake at index 2 is the snowflake at index 0 shifted left by two positions, so they are identical. ```text Input: snowflakes = [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [1, 2, 3, 4, 5, 7]] Output: False ``` Rotation and reflection only reorder the arms, so identical snowflakes must hold the same values. Each of these three has a different set of values, so no pair matches. ```text Input: snowflakes = [[1, 2, 3, 4, 5, 6], [4, 3, 2, 1, 6, 5]] Output: True ``` Reversing the first snowflake gives `[6, 5, 4, 3, 2, 1]`, and shifting that left by two positions gives `[4, 3, 2, 1, 6, 5]`. No plain rotation of the first snowflake matches the second, so this pair needs the reflection.

Overview: Decide whether any two six-arm snowflakes in a list of up to 100,000 match when one may be rotated or mirrored. Tests reasoning about equivalence under rotation and reflection and detecting duplicates at scale without comparing every pair.

Patreon logo
Patreon
Nov 25, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

You are given a list of snowflakes snowflakes, where each snowflake is an array of 6 integers describing its arms in order. Determine whether any two snowflakes are identical.

Two snowflakes are identical if one can be obtained from the other by:

  • a rotation, which is a cyclic shift of the 6 arms, or
  • a mirror reflection, which reverses the arms and then applies any cyclic shift.

Return True if any such pair exists in the list, otherwise return False.

Function Signature

def has_identical_snowflakes(snowflakes: list[list[int]]) -> bool:

Rules

  • A pair means two different positions in the list. Two entries with exactly the same values are identical (a shift by zero), so they count as a pair.
  • A list with a single snowflake has no pair, so the answer is False .

Constraints

  • 1 <= len(snowflakes) <= 10^5
  • len(snowflakes[i]) == 6
  • 0 <= snowflakes[i][j] <= 10^9

Examples

Input: snowflakes = [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 7], [3, 4, 5, 6, 1, 2]]
Output: True

The snowflake at index 2 is the snowflake at index 0 shifted left by two positions, so they are identical.

Input: snowflakes = [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [1, 2, 3, 4, 5, 7]]
Output: False

Rotation and reflection only reorder the arms, so identical snowflakes must hold the same values. Each of these three has a different set of values, so no pair matches.

Input: snowflakes = [[1, 2, 3, 4, 5, 6], [4, 3, 2, 1, 6, 5]]
Output: True

Reversing the first snowflake gives [6, 5, 4, 3, 2, 1], and shifting that left by two positions gives [4, 3, 2, 1, 6, 5]. No plain rotation of the first snowflake matches the second, so this pair needs the reflection.