Registry Synced

Jan 2026 - Python - Week 6 - Collections 5 - Graded

512 words
3 min read

Collections 5 - Graded

Course: Jan 2026 - Python
Collections 5 - Graded
Submission deadline has passed for this assignment
Due Mar 25, 2026 at 11:59 PM IST
Instructions
Use "Test Run" to verify your code with public test cases.
Press "Submit" to have your assignment evaluated.
You can submit your assignment multiple times up until the deadline.
Make sure to submit your final code by the deadline to receive your score.
Summary
100 out of100
Score
Public Tests
3/3 Passed
Submitted on Mar 25, 2026 at 2:35 PM IST
Private Tests
3/3 Passed
Submitted on Mar 25, 2026 at 2:35 PM IST

**Change in eligibility criteria to write oppe2 exam: A5>=40/100 AND A6>=40/100 AND A7>=40/100 AND A8>=40/100. and becoming eligible to give the end term exam.


Sorted string with common characters from two strings.**
Write a function to return a sorted string with unique common charecters present in the given two strings.
Examples
python
>>> common_char_sorted_str('apple', 'ball')
'al'
>>> common_char_sorted_str('abcde', 'edfci')
'cde'
Template Code(Click to Expand)

def common_char_sorted_str(s1:str, s2:str) -> str:
    '''Returns a sorted string with unique common charecters present in the given strings.

    Arg:
        s1 (str) : Input string.
        s2 (str) : Input string.

    Returns:
        str: string of unique common charecters arranged in ascending order.

    Examples:
    >>> common_char_sorted_str('apple', 'ball')
    'al'
    >>> common_char_sorted_str('abcde', 'edfci')
    'cde'
    '''
    ...

NOTE: You can use the below tools for working out and debugging. Click to open them in new tab.

Public Tests ( 3/3 )

Case 1

Input:
text
is_equal(common_char_sorted_str('apple', 'ball'), 'al')
Expected Output:
text
'al'
Actual Output:
text
'al'

Case 2

Input:
text
is_equal(common_char_sorted_str('abcde', 'edfci'), 'cde')
Expected Output:
text
'cde'
Actual Output:
text
'cde'

Case 3

Input:
text
is_equal(common_char_sorted_str('apple', 'orange'), 'ae')
Expected Output:
text
'ae'
Actual Output:
text
'ae'

Private Tests ( 3/3 )

Case 1

Input:
text
is_equal(common_char_sorted_str('12345', '54321'), '12345')
Expected Output:
text
'12345'
Actual Output:
text
'12345'

Case 2

Input:
text
is_equal(common_char_sorted_str('character', 'charisma'), 'achr')
Expected Output:
text
'achr'
Actual Output:
text
'achr'

Case 3

Input:
text
is_equal(common_char_sorted_str('wireless', 'lesswire'), 'eilrsw')
Expected Output:
text
'eilrsw'
Actual Output:
text
'eilrsw'

💻 IITM Official Solution

python

def common_char_sorted_str(s1:str, s2:str) -> str:
    '''Returns a sorted string with unique common charecters present in the given strings.

    Arg:
        s1 (str) : Input string.
        s2 (str) : Input string.

    Returns:
        str: string of unique common charecters arranged in ascending order.

    Examples:
    >>> common_char_sorted_str('apple', 'ball')
    'al'
    >>> common_char_sorted_str('abcde', 'edfci')
    'cde'
    '''

    return ''.join(sorted(set(s1) & set(s2)))


💻 My Submitted Code

python

def common_char_sorted_str(s1:str, s2:str) -> str:
    '''Returns a sorted string with unique common charecters present in the given strings.

    Arg:
        s1 (str) : Input string.
        s2 (str) : Input string.

    Returns:
        str: string of unique common charecters arranged in ascending order.

    Examples:
    >>> common_char_sorted_str('apple', 'ball')
    'al'
    >>> common_char_sorted_str('abcde', 'edfci')
    'cde'
    '''
    ...

    common = set(s1) & set(s2)
    sorted_chars = sorted(common)
    return "".join(sorted_chars)

Document Outline
Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.