Name game|Lowe's codeathon round 1 soluton help needed
Anonymous User
629

You are given an array names consisting of n strings.
Define a group G(i) for 1<=i<=N of strings using the given algorithm.

  • initialize a queue and add string S(i) in queue,mark index i as visited.

  • while the size of queue is greater then 0

    • set P as string present in front of the queue.
    • pop the front of queue
    • for all strings S in array names with index unvisited, if the difference between the unique alphabets present is atmost 1 then add 1 in the queue and mark its index as unvisited.
  • Group G(i) consists of all strings from array names that have their index as visited.

If there are 2 names with their set of unique alphabets A and B ,difference of atmost 1 can only mean one of the following:

  • 1 unique charecters with their set of A missing in B. example : A=['A','B','C'] and B=['A','B']
  • 1 unique charecters with their set of B missing in A. example : B=['A','B','C'] and A=['A','B']
  • 1 unique charecters of A replaced by another unique charecter in B . example : A=['A','B','C'] and B=['A','B','D']

output the group with maximum size and minimum total group required .
Sample Test
INPUT
["HARRY","HARI","LATA","LALA","CHAR"]
OUTPUT
3 2

also how much rating would you give this question?

Comments (2)