• 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

Even Odd Series

  • January 6, 2020
  • CODE OF GEEKS
  • 6


Given a string and it contains the digits as well as non-digits. We have to find the largest even number from available digits after removing the duplicates. If not possible, print -1.

Input : 

First Input : String

Output : 

Largest number

Sample Testcases :

I/P 1:

%#32%#%2

O/P 1:

32

I/P 2:

%#2373#@

O/P 2:

732

Solution : 



def largeeven(lst):
    if(res[-1]%2==0 or res[-1]==0):
        return res
    else:
        for j in range(1,len(lst)+1):
            if(res[-j]%2==0 or res[-j]==0):
                ev=res.pop(-j)
                res.append(ev)
                return res
            else:
                return -1
s1=set()
s=str(input())
for i in s:
    if i.isdigit():
        s1.add(int(i))
res=sorted(s1,reverse=True)
print(largeeven(s1))
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 Pronic Number
  • Next String of Brackets

6 comments on “Even Odd Series”

  1. anonymous says:
    June 3, 2020 at 6:00 pm

    import string
    s=input()
    l=[]
    for i in s:
    if i in string.digits:
    l.append(i)
    l=list(set(l))
    print(”.join(map(str,sorted(l,reverse=True))))

    Reply
  2. anonymous says:
    June 3, 2020 at 6:02 pm

    sorry for indentation ‘if’ inside ‘for’ and ‘l.append’ inside ‘if ‘

    Reply
  3. anonymous says:
    June 3, 2020 at 6:02 pm

    Hope this helps you all 🙂

    Reply
  4. anonymous says:
    June 3, 2020 at 6:06 pm

    import string
    s=input()
    l=[]
    for i in s:
    if i in string.digits:
    l.append(i)
    l=list(set(l))
    print(”.join(map(str,sorted(l,reverse=True))))

    Reply
  5. Saloni Jain Saloni Jain says:
    April 16, 2021 at 4:50 am

    import re
    n=input()
    digits=list(set(re.findall(‘\d’,n)))
    digits.sort()
    digits.reverse()
    num=int(“”.join(digits))
    if num%2==0:
    print(num)
    else:
    l=len(digits)
    for i in range(len(digits)-1,0,-1):
    if int(digits[i])%2==0:
    a=digits[i]
    digits.remove(a)
    digits.insert(l-1,a)
    even=int(“”.join(digits))
    print(even)
    break;
    else:
    print(-1)

    Reply
  6. Saloni Jain Saloni Jain says:
    April 16, 2021 at 4:52 am

    last else loop is execute with for loop:

    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

TCS Reasoning 2021
  • October 4, 2021
TCS Verbal 2021
  • October 4, 2021

Copyright 2021 CODE OF GEEKS. All Rights Reserved.

  • →