Game: Level Difficulty

10pts
Electronic Arts

Problem Statement

Game designers at Epic Games need to ensure a smooth difficulty curve. A level that is suddenly much harder than the previous one can cause players to quit (churn).

Write a query to identify levels where the Fail Rate is at least 10 times higher than the Fail Rate of the immediately preceding level for that specific game.

Rules:

  • Fail Rate is defined as: (attempts_failed / attempts_total).
  • Levels are sequential (1, 2, 3...).
  • Level 1 cannot have a previous level; ignore it for spike detection.
  • A spike is defined as: Current Fail Rate >= 10 * Previous Level Fail Rate.
  • If the previous level had a Fail Rate of 0, any current level with a Fail Rate > 0 should be considered a spike.
  • Output columns: game_id, level_number, current_fail_rate, previous_fail_rate.
  • Result must be sorted by game_id ascending, then level_number ascending.
Tests your understanding of
Window Functions, LAG and Arithmetic Operations

Input Tables

level_stats
game_id(INTEGER)level_number(INTEGER)attempts_total(INTEGER)attempts_failed(INTEGER)
11100050
1290045
13800500
1430020
215005
2245090
2330010
311000
3210015

Expected Output

game_id(INTEGER)level_number(INTEGER)current_fail_rate(DECIMAL)previous_fail_rate(DECIMAL)
130.6250.05
220.20.01
320.150

Tags

HardWindow FunctionsLAGArithmetic Operations
25-35 min
38%

Hints