• Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
CODE OF GEEKS

We at CODE OF GEEKS, aim at providing best and quality content for our users at no extra cost.

    • Study Materials – Company wise
      • Infosys Archive
      • Accenture Archive
      • AMCAT Archive
      • Capgemini Archive
      • Cisco Archive
      • CoCubes Archive
      • Cognizant(CTS) Archive
      • Dell Archive
      • Deloitte Archive
      • DXC Archive
      • Goldman Sachs Archive
      • Hexaware Technologies Archive
      • LTI Archive
      • MindTree Archive
      • TCS Archive
      • Virtusa Archive
      • Wipro Archive
    • Interview Preparation – E Books
      • C Interview Questions
      • Data Structures Interview Questions
      • DBMS Interview Questions
      • HR Interview Questions
      • Java Interview Questions
      • Operating System Interview Questions
      • Python Interview Questions
      • SQL Query Interview Questions
    • Programming
      • C Programming MCQs
      • C Code Snippets – Output Questions
      • Python Code Snippets – Output Questions
    • Aptitude
      • Verbal Ability for Placements
      • Quant for Placements
    • Register
    • Login
  • [email protected]
  • ..
Login / Register
Apply Now
CODE OF GEEKS
CODE OF GEEKS
  • Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
0

Cart

Two Numbers

  • January 9, 2020
  • CODE OF GEEKS
  • 2

You are given a list of numbers from 1 to 9, in which each word is seperated by ‘,’. Your job is to find the sum of two numbers. These two numbers are needed to be calculated as per following rules : 

1. First number should be calculated as :

Add all the numbers that do not come between  5 and 8 in the input.

2.  Second number should be calculated as :

Append all the numbers to each other that comes between 5 and 8 (inclusive).

Find the sum of both numbers.

Note : 5 always comes before 8.

Number of 5’s = Number of 8’s. 

Input : 

First Input : List of numbers

Output : 

“Sum of both numbers”



Sample Testcases :


I/P 1:

3,4,5,2,7,9,8,3,2

O/P 1:

52810

Solution : 

#taking list as input where each element is seperated by ','
lst = list(map(int,input().split(",")))

#find sum of numbers that occur before 5
a = sum(lst[:lst.index(5)])

#find sum of numbers that occur after 8
b = sum(lst[lst.index(8)+1:])

#finding first number
n1 = a+b

#finding second number
rest = lst[lst.index(5):lst.index(8)+1]
n2 = ""
for i in rest:
    n2+=str(i)
print(int(n2)+n1)


Tags: infosys last year handson problemsinfytqinfytq examinfytq examinationinfytq handson problems last yearinfytq handson problems of last yearinfytq handson questionsinfytq last year problemsinfytq last year questionsLast year questions Infytqpractice infyprepare infytq question
  • Previous 100 Most Asked C Interview Questions
  • Next INFOSYS HIRING PROGRAM – HACK WITH INFY 2020

2 comments on “Two Numbers”

  1. RISHABH GUPTA says:
    June 2, 2020 at 6:34 pm

    #TEST CASE PROBLEM

    INPUT:
    1,2,3,5,3,2,5,3,1,8,1,2,1,4,8,1,4,1
    (satisfying both input condition :
    no. of 5=no. of 8
    5 always comes before 8)

    INPUT1:
    5325346(5325318+1+2+3+1+2+1+4+8+1+4+1) #AS PER THE ABOVE CODE

    OUTPUT2:
    532531812160(532531812148+1+2+3+1+4+1) #AS PER MY CODE,WHERE I CHOOSE THE NUMBER STARING FROM 5 AND END WITH 8,HAVING MAXIMUM LENGTH.

    #MY CODE

    l=list(map(int,input().split(“,”)))
    rev=l[::-1]
    start=l.index(5)
    end=len(l)-rev.index(8)
    string=”
    for i in range(start,end):
    string+=str(l[i])
    string2=sum(l[:start])+sum(l[end:])
    print(int(string)+string2)

    Reply
    1. ganesh says:
      February 20, 2021 at 5:58 am

      #code if there are 1 or more than 1 5’s and 8’s
      lst = list(map(int, input().split(‘,’)))

      b = []
      a = 0

      def calc(c):
      global a
      #global c
      global b
      if c == len(lst):
      return
      for i in range(c, len(lst)):
      if lst[i] != 5:
      a = a + lst[i]
      #print(a)
      c = i
      else:
      break
      if c+1 == len(lst):
      return
      for i in range(c+1,len(lst)):
      if lst[i] == 8:
      b.append(str(8))
      c = i+1
      calc(c)
      break
      else:
      b.append(str(lst[i]))
      return

      calc(0)
      #print(b,a)
      res = int(”.join(b))
      outt= res+a
      print(outt)

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CODE OF GEEKS

Subscribe to Newsletter

CODE OF GEEKS

Learn | Code | Achieve

Reach us

[email protected]
We at CODE OF GEEKS, aim at providing quality content to our users at no cost.
CODE OF GEEKS

Important Pages

About us
Advertise
Privacy Policy
Terms and Conditions

Placements – Study Materials

TCS NQT     Wipro     CapGemini
Accenture     MindTree     CTS
DXC     Hexaware Technologies     AMCAT
CoCubes     Goldman Sachs     Dell
Cisco     Deloitte     Virtusa     LTI     Infosys   

Courses

  • Mail Us
  • Login/Register

Recent Posts

What is Cloud Computing | Cloud Computing Applications | Cloud Development Models| SaaS vs PaaS vs IaaS
  • October 23, 2021
What is Amazon Web Services | AWS Regions & AZs | Different AWS Services
  • October 19, 2021

Copyright 2021 CODE OF GEEKS. All Rights Reserved.

  • →