All Tracks Data Structures Hash Tables Basics of Hash Tables Problem

Little Jhool and the matchmaker
Tag(s):

Ad-Hoc, Easy-Medium, Easy-Medium, Hashing

Problem
Editorial
Analytics

Little Jhool is back, with his matchmaker friend Dawgie.

Dawgie's logic for approving a girl with a boy or a boy with a girl, is simple: if the name of a girl has maximum similar characters to the name of a guy, they are definitely not fit for being with each other. For example, a couple with Shubhami and Shubham is less ideal than a couple with Shubham and Dhinsat. Since Shubhami and Shubham have 6 characters in common while the other couple has 3 characters in common, so the other couple is much more ideal.

Now our Little Jhool gives the list of all the crushes in his life to Dawgie, and asks him to tell the top K numbers of girls out of the list of N girls, he gives who'll be a good match for Little Jhool.

Note-1: The case of the letters does NOT matter.
Note-2: The name of Little Jhool is: "LittleJhool", without the space and quotes, where the unique characters present in his name are: [l, i, t, e, j,h,o].
Note-3: In case of a tie, print the names in order of their occurrence.

Input format:
The first line contains an integer, T, denoting the number of test-cases possible. The first line for every test case would contain two integers denoting the values of N and K. The next line would contain N names separated by a space.

Output format:
Print the names of the top K girls who will be a good match for our Little Jhool.

Constraints:
$$1$$ ≤ Test Cases ≤ $$50$$
$$1$$ ≤ N ≤ $$2000$$
$$1$$ ≤ K ≤ N.
$$1$$ ≤ Length of names ≤ $$26$$.

SAMPLE INPUT
3
5 1
jhoolz littleboy cooldude findingathar findingnemo
3 1
bawa chunnu kundan
3 2
kaddu babykaddu littlejhool
SAMPLE OUTPUT
cooldude
bawa
kaddu babykaddu
Explanation

In test number 1, 'cooldude', findingnemo' and findingathar' have 3 common characters. 'jhoolz' has 4 common characters and 'littleboy' has 5 common characters. But since cooldude occurs first, 'cooldude' is the answer.

Time Limit: 2.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

Code Monk (Hashing)

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications