Question: Seclore | JumpTheQ | Hackathon | 2023 | Merging Duplicate Contacts
6
Entering edit mode

Merging Duplicate Contacts

You're writing an Android app whoch merges duplicate contacts from the Contact list of the user's phone.

Contact

  • A contact may have the following fields 
    • Name
      • Type: string
      • Required/Optional : Required
      • Example : bob parson
    • Birthdate 
      • Type: string
      • Required/Optional : Optional , may be an empty  string 
      • Format: DD-MM-YY
      • Example : 13-10-1999
    • Phones
      • Type: List[string]
      • Required/optional : Optional, The list may be empty
      • Example :  [ 8888888888 , +919999999999 , 102 , (022)-2871-5672]
    • Last Updated Time:
      • Type:Integer
      • Required/Optional : Required
      • Description : A higer value means a more recent contact
      • Example : 10256

Phone Number 

  • A contact may have zero or more phone numbers present
  • There could be max one empty phon enumber in a contact  : Eg : ["8888888888","", "9999999999"]
  • A given phone number value can only appear once in a contact list 

Duplicates:


2 contacts are considered duplicates phone numbers matches

Merging 

  • Contacts should be merged if found to be duplicates . After merging the most recent contact should remain 
  • The contacts should have values in all fields which had non- empty values in either of the 2 contacts before merging 
  • The phone numbers list of both the duplicate contacts should be merged too 

 

Your Task:


Write a function to read contacts, merge duplicates and print the merged  output to console

Input format:

First line contains a single integer N, the number of contacts
Then N groups of lines follow, one group for each contact. Each group has the following format:

  • The first line contains a string CN, the name of contact
  • The next line contains a string B, the birth date of the contact
  • The next line contains single integer P. the total number of phones for this contact
  • The next line contains P space separated strings, the phone
  • this contact. If P is O, this Us a blank line. numbers for the last update time
  • The next line contains a single integer U.The last update time the contact

Output format

 

  •  M group of lines of contact details, where M is number of contacts ate
  •  Each group of lines of merged contact detail has following format
  •  The first line must contain a single string, the Contact Name
  •  The next line must contain a single string, the contacts birth-daft
  •  The next line must contain the list of the contact's phone numbers
  • separated strings, in ascending order. If phones ist is empty, thas a al
  •  The next line must contain a single integer, the contacts last update an
  •  The contacts must be printed in ascending order of their names

NOTE: You will be provided code snippets of functions to parse the input for and print the output to console. The code snippets will contain logic to print in ascending and too. You are requested not to change the code inside these snippets Doing to may as
vour program failing for certain test cases

Constraints 

• 1 <= N < 1000
• 0 <= P <= 10
• 0 <= U <= 1000000
No two contacts in the input will have the same value of U fast Uposte
• If one of the optional fields is blank, the special value "empt/will agent line for that field. This may happen for a birthdate or a phone number The see
empty' appearing in the input he should be treated as an empty string value. While printing output, if any of the values is ensely, you must pent its place.


• Assume that all inputs will be in valid format You dont need to validate the value . For example, assume that the birth-date validate the format need to validate
id format and you don't need to validate the format 

 

 

Explanation:
'alice' and 'Alice Weasley' have the phone number '123456)
hence they're duplicates and merged in the final output.
The merged contact has the name *Alice Weasley because Weasley has the more recent last update time, 20.
'alice' has the birthdate '05-06-2000" present but *Alice W
the birthdate field empty.
The merged contacts has the
present, merged from the older contact, 'alice'.
Note: The 'empty' phone is printed first because the empty str
first in ascending order.

 

Example
Input


3
alice
05-06-2000
3
12345678 empty (022) 2456-7890
Bob Parson

empty
+9156728192
10
Alice Weasley
empty
2
12345678 98765432
20


Output


Alice Weasley
05-06-2000
empty 12345678 (0221-2456-7890 9
20
Bob Parson
empty
+9156728192

ADD COMMENTlink 17 months ago PoGo 2.4k
0
Entering edit mode

chech

ADD COMMENTlink 13 months ago Prabhat Kumar Mishra • 0

Login before adding your answer.

Similar Posts
Loading Similar Posts