Array ( [0] => [1] => questions [2] => Basic [3] => Alpha-Numeric-Sorting )
Given text comprising of words and numbers, sort them both in ascending order and print them in a manner that a word is followed by a number. Words can be in upper or lower case. You have to convert them into lowercase and then sort and print them.
First line contains total number of test cases, denoted by N
Next N lines, each contains a text in which words are at odd position and numbers are at even position and are delimited by space
Constraints:
1. Text starts with a word
2. Count of words and numbers are the same.
3. Duplicate elements are not allowed
4. Words should be printed in lower case.
5. No special characters allowed in text.
Words and numbers sorted in ascending order and printed in a manner that a word is followed by a number.
2 Sagar 35 sanjay 12 ganesH 53 ramesh 19 Ganesh 59 suresh 19 rakesh 26 laliT 96
ganesh 12 ramesh 19 sagar 35 sanjay 53 ganesh 19 lalit 26 rakesh 59 suresh 96
3 SteveJobs 40 TimBerners-Lee 70 BillGates 45 JamesGosling 60 LinusTorvalds 35 RichardStallman 54 SatyaNadellea 30 SundarPichai 28 MarkZuckerberg 35 AzimPremji 30
billgates 40 stevejobs 45 timberners-lee 70 jamesgosling 35 linustorvalds 54 richardstallman 60 azimpremji 28 markzuckerberg 30 satyanadellea 30 sundarpichai 35
2 Microsoft 78 Google 28 Facebook 34 Oracle 36 Cognizant 73 IBM 67 TCS 63
facebook 28 google 34 microsoft 78 cognizant 36 ibm 63 oracle 67 tcs 73
Login to see Discussion
Seggregate the even indices and odd indices to 2 different arrays.
Convert the words into lowecase words.
Sort words and numbers differenlty.
Iterate a loop and print the values alternately.
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution