Finding unique pairs in lottery tickets I was trying to solve one of the hackerrank practice questions. Could anyone please let me know how can I make this code much effective, in terms of time and space complexity?


  The Super Bowl Lottery is about to commence, and there are several
  lottery tickets being sold, and each ticket is identified with a
  ticket ID. In one of the many winning scenarios in the Superbowl
  lottery, a winning pair of tickets is:
  
  
  Concatenation of the two ticket IDs in the pair, in any order,
  contains each digit from 0 to 9 at least once.  
  
  
  For example, if there are 2 distinct tickets with ticket ID 12930455 and 56789, (129300455, 56789) is a winning pair.
  
  NOTE: The ticket IDs can be concantenated in any order. Digits in the
  ticket ID can occur in any order.
  
  Your task is to find the number of winning pairs of distinct tickets,
  such that concatenation of their ticket IDs (in any order) makes for a
  winning scenario. Complete the function winningLotteryTicket which
  takes a string array of ticket IDs as input, and return the number of
  winning pairs.
  
  Input Format
  
  The first line contains n denoting the total number of lottery tickets
  in the Super Bowl. Each of the next n lines contains a string, where
  string on a ith line denotes the ticket id of the ith ticket.
  
  Constraints  
  
  
  [1 &le; pretty much everything  input &le; 10⁶]
  Each ticket id consists of digits from [0, 9]
  
  
  Output Format
  
  Print the number of pairs in a new line.
  
  Sample Input

5  
129300455  
5559948277  
012334556  
56789  
123456879  

  
  Sample Output

5





import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
    static Long winningLotteryTicket(String[] tickets) {
        int count = 0;
        for(int i = 0 ; i &lt; tickets.length-1 ; i++) {
            for(int j = i+1 ; j &lt; tickets.length ;j++ ){
               if(!(tickets[i]).equals(tickets[j]) &amp;&amp; getStatus(tickets[i],tickets[j])){
                   count++;
               }
            }
        }
        return Long.valueOf(count);
    }

    public static boolean getStatus(String a, String b){
        String c = a+b;
        if(c.length() &lt; 10){
            return false;
        }
        Set&lt;Character&gt; charSet = new HashSet&lt;&gt;();
        char[] arr = c.toCharArray();
        for(int i = 0; i &lt; arr.length; i++){
            charSet.add(arr[i]);
        }

        if (charSet.size() == 10){
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String[] tickets = new String[n];
        for(int tickets_i = 0; tickets_i &lt; n; tickets_i++){
            tickets[tickets_i] = in.next();
        }
        Long result = winningLotteryTicket(tickets);
        System.out.println(result);
        in.close();
    }
}
try-with-resources

Since Java 7, you can use try-with-resources for safe and efficient handling of the underlying I/O resource.

return boolean

if (condition) {
    return true;
} else {
    return false;
}


This kind of code can be simplified as return condition.

Method names

Your naming can be better refined to reflect what they are doing. For example, getStatus can be renamed as hasUniqueNumerals, following the standard is/has prefix for methods returning a boolean. winningLotteryTicket can be renamed as countWinningPairs.

for-each loop

Your loop on c.toCharArray() can also be written as:

for (char current : c.toCharArray()) {
    charSet.add(current);
}


What's nice


You checked if the concatenation of the two inputs will give you 10 or more digits, returning false first if not.
You declared charSet as a Set rather than a HashSet and relied on generic type inference.