⌘K
Flycodx

Sensor Grid Anomaly Detection

Sensor Grid Anomaly Detection

HardArrays100% accepted

A smart farming operation in Punjab uses a 2D sensor grid to monitor soil moisture. An anomaly region is defined as a rectangular area where the difference between max and min values exceeds a threshold T. Find all such regions and their anomaly score (max - min). Rule: count ALL axis-aligned subrectangles (any size >= 1x1) where max-min > T. Your solve(...) function receives the inputs as ready-made arguments — no input reading or parsing needed; just return the answer.

Approach

Given an M×N grid of sensor readings, find all subarrays where (max - min) > T and return count of such subarrays with their maximum difference.

Input

grid=[[10,15,12],[18,22,20],[14,16,19]] t=4

Output

19
solution.py
Loading editor...
Test 1
Test 2
Test 3

Press Run to test your custom input, or Submit to judge against all test cases.

Sign in to continue

Create a free account to run code, submit solutions and track progress.

  • Free forever — no credit card
  • 10+ languages with live execution
  • Points, streaks & leaderboards
Auto Save OnLn 1, Col 1Spaces: 4UTF-8LFPython 3