How far apart are two scheduled days
Two events were scheduled on different days. Return the absolute difference.
- Both values are day numbers counted from a common origin.
- The answer is the non-negative distance between them.
RescheduleDays(originalDay: int, newDay: int) → int
C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
public int RescheduleDays(int originalDay, int newDay) {
}
Worked examples
| Call | Result |
|---|---|
RescheduleDays(3, 7) | 4 |
RescheduleDays(7, 3) | 4 |
RescheduleDays(5, 5) | 0 |
RescheduleDays(0, 1) | 1 |
Hint
Subtract and take the absolute value.
Reference solution in C#
public int RescheduleDays(int originalDay, int newDay) {
return Math.Abs(newDay - originalDay);
}