329. Max Element in Linked List

EasyLinked ListLinked ListTraversalMax

Given the head of a singly linked list, return the maximum value among all node values.

Input: Head of a singly linked list (at least one node).

Output: Integer — maximum node value.

Examples

Example 1
Input: [3,1,4,1,5,9,2,6]
Output: 9
Explanation: Traverse all; max is 9.
Example 2
Input: [-5,-1,-3]
Output: -1
Explanation: All negatives; max is -1.
Example 3
Input: [7]
Output: 7
Explanation: Single node; max is 7.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →