Problem: Consider a non-empty input array (inarr) containing non-zero positive Integer. From input array, identify the unique pairs of integers such that each of the integers in the pair have the same sum of the digits. Print outnum, the number of unique pairs identified satisfying the criteria. If no such pair of integers can be identified print -1.
Input format: Read the array inarr (input array) with the elements separated by ‘,’ (comma)
Output format: Print outnum or -1 accordingly
Sample Input:
34,89,6,321,53,45,2211,81
Sample Output:
4
Explanation: All the possible combinations are: (6, 321), (6, 2211), (321, 2211), (45, 81)
First combination: 6, 3+2+1 = 6
Second combination: 6, 2+2+1+1 = 6
Third combination: 3+2+1 = 6, 2+2+1+1 = 6
Fourth combination: 4+5 = 9, 8+1 = 6
Hence the output will be: 4 (Output)
Solution: We strongly recommend you to try the problem first before moving to the solution.
Python
# Python code for Unique Pairs and Digit Sum
# www.codewindow.in
import math
list_num=input().split(',')
sum_dig_list=[]
for num in list_num:
sum_dig=sum(list(map(int, num)))
sum_dig_list.append(sum_dig)
max_sum=max(sum_dig_list)
list_digit_count=[0]*(max_sum+1)
for num in sum_dig_list:
list_digit_count[num] += 1
total_pair=0
for count in list_digit_count:
if count>1:
total_pair += int(math.factorial(count)/(math.factorial(count-2)*2))
if total_pair==0:
print('-1')
else:
print(total_pair)
Input:
34,89,6,321,53,45,2211,81
Output:
4
Follow Us
You Missed
- Unlocking Innovation and Diversity: Accenture HackDiva Empowers Women in Tech with Cutting-Edge Solutions – codewindow.in
- QA Engineer Opportunities at Siemens Company: Apply Now – codewindow.in
- QA Engineer Opportunities at Siemens Company: Apply Now – codewindow.in
- Software Engineer Positions at Siemens Company: Apply Now – codewindow.in
- Cloud Engineer II Opportunities at Insight Company: Apply Now – codewindow.in
- Shape Your Career: Assistant Engineer Opportunities at Jindal Company – codewindow.in
- Shape Your Future: Executive Opportunities at Jindal Company – cdewindow.in
- Associate Engineer, Software Development at Ingram: Apply Now – codewindow.in
- Jade Company’s UI/UX Development Engineer Opportunities – Apply Now – codewindow.in
- Transform Your Career with S&P Global: Apply for the Software Development Engineer Role and Lead the Future of Financial Technology Innovation – codewindow.in
- Unlock Your Potential at Accenture as an Associate Software Engineer – Elevate Your Career with Innovation and Excellence – codewindow.in
- Accelerate Your Career: Join NVIDIA’s Elite Software Engineering Internship Program and Shape the Future of Technology – codewindow.in
- C Programming Interview Questions – codewindow.in
- Lead the Way in Analytics: Specialist Position at Razorpay – codewindow.in
- Innovate with Cyient: Junior Software Engineer Wanted – codewindow.in
- Innovate with Volvo: Associate Software Engineer Wanted – codewindow.in
- Lead the Tech Revolution: Full Stack Developer at Unisys – codewindow.in
- Software Engineer at ABB: Unlock Innovation and Shape the Future – codewindow.in
- IBM Associate Systems Engineer Job: Boost Your Career with a Leading Technology Giant – codewindow.in
- Make Your Mark in Android Development: Join Concentrix – codewindow.in
- Infosys is Growing: Field Services Developer Role Now Open – codewindow.in
- Start Your IT Career Journey with Amazon: IT Services Support Associate I Opportunity – codewindow.in
- Shape the Future of Web: Front-End Software Engineer Opportunity at Google Cloud – codewindow.in
- Barclays QA Team Expands: QA Analyst Role Now Open- codewindow.in
- Eurofins QA Team Grows: Test Engineer Role Now Open – codewindow.in
- Exciting Opportunity: Java Spring Boot Senior Developer Role at Infosys – codewindow.in
- Unlock Your Potential at Nokia: Software Engineer Opportunities Await – codewindow.in
- Join Microsoft’s World-Class Team as a Software Engineer and Shape the Future of Technology – codewindow.in
- Virtusa is Seeking Talented React JS Developers to Drive Digital Excellence – codewindow.in
- Join IBM Dynamic Team as a Full Stack Developer and Shape the Future – codewindow.in
- EY Welcomes Aspiring AI/ML Interns to Unlock the Future of -codewindow.in
- Exciting Opportunity: Project Engineer at Rockwell Automation- codewindow.in