High-Margin Products

Easy
Arithmetic
Filtering

High-Margin Products

The products table contains selling prices and costs.

Return product_id, product_name, margin for products whose margin (price - cost) is greater than 20. Round margin to 2 decimal places and sort by product_id ascending.

Browser Engine: Evaluates PySpark DataFrame & SQL logic locally in Pyodide WebAssembly.

Input data

1 DataFrame

These DataFrames are passed to solve(spark, dfs). Access one with dfs['name'].

df.products5 rows
product_id (int)product_name (string)price (double)cost (double)
1Desk8050
2Lamp4030
3Chair12075
4Mug155
5Shelf6035

Return these columns

product_id(int)
product_name(string)
margin(double)

Column names and order must match. Sort order is specified in the question.

Browser engine
Loading Python editor…
Click Run to try the sample cases, or Submit to check the hidden cases. First run caches the browser Python engine (~8–15s once); all code stays on your device.