Previous Next
0 / 6
Module DEMO-32-57DEMO-C-32

Interval Relationship

DEMO-C-32 β€’ Programming in C

Browser-only practice

Problem Statement

Problem Description

You are given two closed intervals, A and B. Each interval is defined by a pair of integers:

  • Interval A: [l1, r1]
  • Interval B: [l2, r2]

Your task is to determine the relationship between these two intervals. There are five possible relationships:

  1. Disjoint: The intervals do not overlap or touch.
  2. Touching: The intervals touch at exactly one point (e.g., [1,3] and [3,5]).
  3. Overlapping: The intervals partially overlap but neither contains the other.
  4. A contains B: Interval A fully contains interval B.
  5. B contains A: Interval B fully contains interval A.

Examples

  • Input: 1 5 6 9 β†’ Output: Disjoint
  • Input: 2 8 3 7 β†’ Output: A contains B

Analyze the intervals and print the correct relationship.

Constraints

$-10^9 \leq l1, r1, l2, r2 \leq 10^9$ $l1 \leq r1$ $l2 \leq r2$

Input Format

A single line containing four space-separated integers: l1 r1 l2 r2

  • l1, r1: the start and end of interval A
  • l2, r2: the start and end of interval B

It is guaranteed that l1 ≀ r1 and l2 ≀ r2.

Output Format

Print exactly one of the following strings on a single line:

  • Disjoint
  • Touching
  • Overlapping
  • A contains B
  • B contains A

No extra spaces or formatting are allowed.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
1 5 6 9
Disjoint
Intervals [1,5] and [6,9] do not overlap or touch.
Sample #2
Public sample
2 8 3 7
A contains B
Interval [2,8] fully contains [3,7].
Sample #3
Public sample
3 7 2 8
B contains A
Interval [2,8] fully contains [3,7].
Sample #4
Public sample
1 5 3 7
Overlapping
Intervals [1,5] and [3,7] overlap but neither contains the other.
Sample #5
Public sample
4 10 1 6
Overlapping
Another overlapping case.
Sample #6
Public sample
1 5 5 9
Touching
Intervals [1,5] and [5,9] touch at point 5.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings