Omid - Challenge 286

data-challenges
advanced-exercises
🔰 Question Result ID Col1 Col2 Col3 P O
Published

March 24, 2026

Illustration for Omid - Challenge 286

Challenge Description

🔰 Question Result ID Col1 Col2 Col3 P O

Solutions

library(tidyverse)
library(readxl)

path = "files/200-299/286/CH-286 Advanced Filtering.xlsx"
input = read_excel(path, range = "B2:E9")
test  = read_excel(path, range = "G2:G4") %>% pull()

result = input %>%
  pivot_longer(-ID) %>%
  mutate(n = n(), .by = value) %>%
  summarise(sum = sum(n), .by = ID) %>%
  filter(sum == 3) %>%
  select(ID) %>%
  pull()

# should be 2 and 4, but provided answer is 2 and 5.
  • Logic:

    • Reads the workbook ranges needed for the challenge

    • Reshapes the data into the grain required by the task

    • Aggregates or ranks values at the relevant grouping level

    • Builds the intermediate columns that drive the final result

  • Strengths:

    • The R solution stays close to the workbook rule and keeps the transformation compact.
  • Areas for Improvement:

    • The code assumes the sheet structure and source ranges remain stable.
  • Gem:

    • The strongest part of the solution is choosing the right intermediate representation before shaping the final output.
import pandas as pd

path = "200-299/286/CH-286 Advanced Filtering.xlsx"
input = pd.read_excel(path, usecols="B:E", skiprows=1, nrows=8)
test = pd.read_excel(path, usecols="G", skiprows=1, nrows=2)['IDs'].tolist()

result = (
    input.melt(id_vars="ID")
         .groupby("value")["ID"].transform("count")
         .groupby(input.melt(id_vars="ID")["ID"]).sum()
         .loc[lambda x: x == 3]
         .index.tolist()
)

print(result)
print(test)
# should be 2,4, and provided answer is 2,5
  • Logic:

    • Reads the workbook ranges needed for the challenge

    • Reshapes the data into the grain required by the task

    • Aggregates or ranks values at the relevant grouping level

  • Strengths:

    • The Python version follows the same rule in a direct dataframe-oriented implementation.
  • Areas for Improvement:

    • The code assumes the workbook layout remains stable, so any sheet redesign would require small adjustments.
  • Gem:

    • The implementation stays close to the original workbook rule instead of adding unnecessary abstraction.

Difficulty Level

This task is moderate:

  • The core logic is clear, but the correct transformation pattern is not obvious from the raw input.

  • The challenge combines multiple reshaping, grouping, or parsing steps.