Problem: A list of numbers will be given, number 5 and 8 will be present in the problem input. (5 will always come before 8).
Step 1: Add all the numbers which don’t lie between 5 and 8 as given in the input statement (excluding 5 and 8 itself).
Step 2: concatenate all the numbers in between 5 and 8 (including 5 and 8)
Step 3: Sum of value of Step 1 and Step 2.
Sample Input:
3,2,6,5,1,4,8,9
Sample Output:
5168
Explanation:
Step 1: sum of 3,2,6,9 since they doesn’t fall between 5 to 8 (excluding 5 and 8). 3+2+6+9=20
Step 2: concatenation of ‘5’, ‘1’, ‘4’, ‘8’ is 5148
Step 3: 20+5148 = 5168 (Output)
Solution: We strongly recommend you to try the problem first before moving to the solution.
Python
# Code to understand the Add and Concatenation problem in Python
# www.codewindow.in
num=input().split(',')
length=len(num)
indexFive=num.index('5')
indexEight=num.index('8')
sum2 = ''
sum1 = 0
for i in range (indexFive, indexEight+1):
sum2 += (''.join(num[i]))
for i in range (0, length):
if(i<indexFive or i>indexEight):
sum1 += int(num[i])
print(sum1+int(sum2))
Input:
3,2,6,5,1,4,8,9
Output:
5168
Follow Us
You Missed
- UKG Hiring for Software Engineer
- 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
- 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
- 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
- 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
- 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
- Wipro is Hiring Test Engineers to Elevate Quality Assurance – codewindow.in
- Deloitte Is Hiring: Analysts and Senior Analysts Wanted to Drive Innovation – codewindow.in
- Exciting Software Development Opportunity At Oracle – codewindow.in
- PayPal Hiring Data Analyst 1 – codewindow.in
- SIEMENS HEALTHINEERS Hiring Data Scientist ( ML & AI) – codewindow.in
- Programming in C++ – codewindow.in
- Programming in C++ – codewindow.in
- Unstop Hiring Challenges Internships and Hackathons – codewindow.in
- Programming in Python – codewindow.in
- Programming in Python – codewindow.in
- Programming in C++ – codewindow.in
- Programming in C++ – codewindow.in
- Programming in C++ – codewindow.in
- Programming in C++ – codewindow.in
- Programming in C++ – codewindow.in
- Data Structure – comprehensive guide – codewindow.in