Company: Amazon HackOn
Difficulty: easy
You are given a linked list where each node has three attributes: tagName — a single lowercase character representing the tag name. number — an integer associated with the tag. next — a reference to the next node in the list. Sort the linked list using the following criteria: Primary criterion: sort the nodes by their tagName in alphabetical order. Secondary criterion: if two nodes have the same tagName , sort them by their number in ascending order. After sorting the linked list, print the elements of the sorted list. Input Format N tagName_1 number_1 tagName_2 number_2 ... tagName_N number_N The first line contains an integer N , the size of the linked list. Each of the next N lines contains a character tagName and an integer number separated by a single space, describing one linked-list element in list order. Output Format Print N lines. Each line contains the tagName and the number of one node of the sorted list, separated by a single space. Constraints 1 ≤ N &