|
U
Pro50. Construct and Print Three-Node Linked List
Easy
Problem Description
Given three integers A, B, and C, construct a singly linked list with three nodes containing these values and print them formatted as A -> B -> C -> NULL.
Input Format
A single line containing three space-separated integers A, B, and C.
Output Format
Print A -> B -> C -> NULL.
Example 1:
Input:
1 2 3
Output:
1 -> 2 -> 3 -> NULL
Explanation: Nodes 1, 2, 3 linked sequentially.
Example 2:
Input:
10 20 30
Output:
10 -> 20 -> 30 -> NULL
Explanation: List of multiples of 10.
Example 3:
Input:
-5 0 5
Output:
-5 -> 0 -> 5 -> NULL
Explanation: Negative and zero values.
Constraints:
Standard integer bounds: 32-bit signed integer or input range [1, 10^5].Time complexity target: O(N) or O(N log N) where applicable.Auxiliary space target: O(1) or minimal auxiliary memory.
Follow up:Can this algorithm be adapted to an online streaming setting where the entire input cannot be held in memory simultaneously?
1,180 Online
Code
|Loading Code Editor...
SavedLn 1, Col 1
input =
Sandboxed Engine
Ctrl+Enter = Run | Ctrl+Shift+Enter = Submit