Drill

ProblemsGo › events

How far apart are two scheduled days

easyeventsMathGo

Two events were scheduled on different days. Return the absolute difference.

rescheduleDays(originalDay: int, newDay: int) → int

Go 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.

Solve it in Python →

Where you start

func rescheduleDays(originalDay int, newDay int) int {
	
}

Worked examples

CallResult
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 Go
func rescheduleDays(originalDay int, newDay int) int {
	diff := newDay - originalDay
	if diff < 0 {
		diff = -diff
	}
	return diff
}

The same problem in another language

More events problems in Go