Given a Linked List consisting of integers, the task is to print the number of distinct absolute values present in the Linked List.

Examples:

_Input: __-1 -> -2 -> 0 -> 4 -> 5 -> 8 _

Output:_ 6 _

Explanation:

Distinct absolute node values are {0, 1, 2, 4, 5, 8}

Input:_ -1 -> -1 -> -1 -> 0 -> 1 _

Output:_ 2 _

Explanation:

_Distinct absolute node values are {0, 1}. _

Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: In order to solve this problem, we require a Set or a HashSet to store the distinct absolute values present in the Linked List. After traversing the entire linked list and inserting absolute values of every node in the Set, the size of the Set gives the number of absolute distinct values present in the Linked List.

#data structures #hash #linked list #searching #hashset #linked lists

Absolute distinct count in a Linked List
3.20 GEEK