CiscoOA #31
Delete Nodes Greater Than X
Estimated EasyJudge-ready
Topics (AI-labelled)Linked Lists
The node values of a singly linked list are given in their original order. Delete every node whose value is greater than x and output the remaining nodes without changing their order; nodes equal to x are kept.
Input
The input is n x, followed by n node values. The original bounds are kept: 1≤n≤100000, 1≤x≤100000, and node values in 1..100000.
Output
Output the remaining node values in their original order, separated by spaces; if all nodes are deleted, output an empty line. Do not output the number of nodes.
Example 1
Input:
4 3
1 5 3 4
Output:
1 3
Example 2
Input:
2 5
5 5
Output:
5 5
Example 3
Input:
2 1
2 3
Output:
Example notes
The outputs of the three public examples are, in order: 1 3; 5 5; empty text. Verified by independent enumeration or direct simulation.
Editorial
Loading solution…