library(tidyverse)
library(readxl)
path = "files/200-299/273/CH-273 Advanced Sorting.xlsx"
input = read_excel(path, range = "B2:E9")
test = read_excel(path, range = "G2:J9")
result = input %>%
rowwise() %>%
mutate(highest_value = max(c_across(starts_with("2"))),
max_col = names(.)[which.max(c_across(starts_with("2")))+1]) %>%
arrange(desc(highest_value), desc(max_col)) %>%
select(-c(highest_value, max_col))
all.equal(result, test, check.attributes = FALSE)
# > [1] TRUEOmid - Challenge 273
data-challenges
advanced-exercises
🔰 Question Result 2023 2024 2025 Product ID MN-11 MN-12

Challenge Description
🔰 Question Result 2023 2024 2025 Product ID MN-11 MN-12
Solutions
Logic:
Reads the workbook ranges needed for the challenge
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/273/CH-273 Advanced Sorting.xlsx"
input = pd.read_excel(path,usecols="B:E", skiprows = 1, nrows=8)
test = pd.read_excel(path, usecols="G:J", skiprows=1, nrows=8).rename(columns=lambda col: str(col).replace('.1', ''))
cols_2 = [col for col in input.columns if str(col).startswith('2')]
input = (
input.assign(
RowMax=input[cols_2].max(axis=1),
RowMaxPos=input[cols_2].idxmax(axis=1).map(lambda col: input.columns.get_loc(col) + 1)
)
.sort_values(['RowMax', 'RowMaxPos'], ascending=[False, False])
.drop(['RowMax', 'RowMaxPos'], axis=1)
.reset_index(drop=True)
)
print(input.equals(test)) # TrueLogic:
Reads the workbook ranges needed for the challenge
Builds the intermediate columns that drive the final result
Applies the rule iteratively until the output stabilizes
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 business rule is readable, but the workbook still requires careful implementation to reach the expected layout.