Partial Digit Sequence

3.2

8 votes
Basic Programming, Basics of Implementation, Easy, Implementation
Problem

You are given an array A of length N. The partial digit subsequence of an array A is a subsequence of integers in which each consecutive integers have at least 1 digit in common. You are required to find the length of longest partial digit subsequence from the given array.

Input : 

  • The first line of input contains N, length of array A.
  • The second line of input contains N space-separated integers representing elements of A.

Output :

  • Print an integer representing the maximum length of the longest partial digit subsequence of the given array A.

Constraints :

  • 1N105
  • 1Ai1018

   

Sample Input
2
12 23
Sample Output
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The longest partial digit subsequence of the given array is [12, 23]. as 12 and 23 contain 2 as the common digit.

Editor Image

?