PIXELBANKv9.1.0
Menu

Dynamic Programming Stereo: Monotonicity Check

Dynamic Programming stereo matching relies on the monotonicity constraint: pixel ordering is preserved between views.

A valid DP path can only move right (i+1,j), down (i,j+1), or diagonal (i+1,j+1).

Violation occurs if: i decreases OR j decreases between consecutive points.

Given a path as list of (i,j) pairs, return True if monotonicity is violated, False otherwise.

Constraints:

  • 3 ≤ path length ≤ 1000
  • 0 ≤ i, j < 1000

Examples:

| Input | Output | |-------|--------| | [(0,0),(1,1),(2,2),(3,3)] | False | | [(0,0),(1,0),(0,1)] | True | | [(0,0),(0,1),(1,1),(1,2)] | False |

Example:

Input:
path = [(0,0), (1,1), (2,2), (3,3)]
Output:
False
Reasoning:
  • We scan consecutive pairs in the path and check if either coordinate ever decreases: from (ik,jk)(i_k, j_k) to (ik+1,jk+1)(i_{k+1}, j_{k+1}), a violation occurs if ik+1<iki_{k+1} < i_k or jk+1<jkj_{k+1} < j_k.
  • For (0,0)→(1,1)(0,0) \to (1,1): 1≥01 \ge 0 and 1≥01 \ge 0, so no violation.
  • For (1,1)→(2,2)(1,1) \to (2,2): 2≥12 \ge 1 and 2≥12 \ge 1, so no violation.
  • For (2,2)→(3,3)(2,2) \to (3,3): 3≥23 \ge 2 and 3≥23 \ge 2, so no violation.
  • Since no step decreases in ii or jj, monotonicity is not violated, so the output is False.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Dynamic Programming Stereo: Monotonicity Check - Hard | PixelBank