Interview Questions/Coding/Directional Value Adjustment

Directional Value Adjustment

Preview mode. Log in to edit, run, submit, and save progress.

Easy

Directional Value Adjustment

A controller changes a value using directional adjustment buttons. In one operation, it may increase the value by any odd positive amount, or decrease the value by any even positive amount. For each pair a and b, compute the minimum number of operations needed to change a into b. Input Format: The first line contains t, the number of test cases. Each test case contains a and b. Output Format: For each test case, print the minimum number of operations.

Examples

Example 1
Input:
1
7 10
Output:
1

Explanation: The value needs to increase by 3, and 3 is an odd positive amount, so one operation is enough.

Approach hint

Start with the simplest clear approach, explain the trade-off, then move toward the cleaner answer.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp