Read Integer data & store data in an array .Display the count of values stored that are single digit.
In c program
Answers
Answer:
Count pairs in an array which have at least one digit common
Given an array of N numbers. Find out the number of pairs i and j such that i < j and Ai and Aj have atleast one digit common (For e.g. (11, 19) have 1 digit common but (36, 48) have no digit common)
Examples:
Input: A[] = { 10, 12, 24 }
Output: 2
Explanation: Two valid pairs are (10, 12) and (12, 24) which have atleast one digit common
Recommended: Please try your approach on {IDE} first, before moving on to the solution.
Method 1 (Brute Force) A naive approach to solve this problem is just by running two nested loops and consider all possible pairs. We can check if the two numbers have atleast one common digit, by extracting every digit of first number and try to find it in the extracted digits of second number. The task would become much easier we simply convert them into strings.
Below is the implementation of the above approach:
Explanation:
follow me pls