Program to delete duplicates from a link list

Python : missing characters : hackerrank solution

Python : missing characters : hackerrank solution Problem:- 

Implement a function that takes a string that consists of lowercase letters and digits and returns a string that consists of all digits and lowercase English letters that are not present in the string. The digits should come first, in ascending order, followed by characters, also in ascending order.

Example

S = “7985interdisciplinary 12”

The returned string is “0346bfghjkmoquwwa It contains all missing digits in ascending order, followed by missing characters in ascending order.

Function Description of Python : missing characters : hackerrank solution

Complete the function missingcharacters in the editor below.

missingCharacters has the following parameter(s):
    string s:  a string
Return:
        string: a string as described above
Code:- 
def missingCharacters(s):
    l=[0]*123
    result=""
    for i in range(len(s)):
        x=ord(s[i])
        l[x]+=1
    for i in range(48,58):
        if(l[i]==0):
            result+=chr(i)
    for i in range(97,123):
        if(l[i]==0):
            result+=chr(i)
    return result
if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    s = input()

    result = missingCharacters(s)

    fptr.write(result + '\n')

    fptr.close()

 

Recommended Post:

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

 

Leave a Reply

Your email address will not be published.