Linked List Strictly Increasing or Decreasing - aloalgo

Linked List Strictly Increasing or Decreasing

Easy

You are given the head of a singly linked list, determine if the list is either strictly increasing or strictly decreasing.

  • A linked list is strictly increasing if for every node, its value is greater than the value of the previous node.
  • A linked list is strictly decreasing if for every node, its value is less than the value of the previous node.

An empty list or a list with a single node is considered to be both strictly increasing and strictly decreasing.

Example 1

Input
1 → 3 → 5 → 8 → null
Output
True
Explanation:

The list is strictly increasing: 1 < 3 < 5 < 8.

Example 2

Input
10 → 7 → 4 → 1 → null
Output
True
Explanation:

The list is strictly decreasing: 10 > 7 > 4 > 1.

Example 3

Input
1 → 3 → 3 → 5 → null
Output
False
Explanation:

The list is not strictly increasing because 3 is not greater than 3.

Example 4

Input
1 → 5 → 2 → null
Output
False
Explanation:

The list is neither strictly increasing nor strictly decreasing.

Loading...
Input
1 → 3 → 5 → 8 → null
Output
True

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!