Last Updated: 12 Sep, 2025

Common Digit Transactions

Moderate
Asked in company
Goldman Sachs

Problem statement

You are given a list of 'N' non-negative transaction IDs. Your task is to perform two operations: a verification check and an audit sum.

  • Verification: Check if for every pair of adjacent transaction IDs in the list, they share at least one common digit.
  • Audit: Calculate the sum of all transaction IDs in the list.

  • The verification is successful only if the common digit condition is true for all adjacent pairs.


    Input Format:
    The first line of input contains an integer 'N', the number of transaction IDs.
    
    The second line contains 'N' space-separated long integers, representing the transaction IDs.
    


    Output Format:
    The first line of output must be either true or false, indicating the result of the verification check.
    
    The second line of output must be a single integer, the total sum of all transaction IDs.
    


    Note:
    If N <= 1, there are no adjacent pairs to check, so the verification is considered true.
    
    Transaction IDs can be large, so use a data type that can handle 64-bit integers (e.g., long in Java, long long in C++).