Hey folks, this article features NPTEL Joy Of Computing Using Python Week 12 Programming Assignment 2025 answers with passed test cases. The previous articles discuss the week 11 programming assignment which passed all the test cases given.Â
If you didn't complete the Week 11 Assignment of Joy of Computing using Python programming, the link is given below.Â
Also Read:Â NPTEL Joy Of Computing Using Python Week 11 Programming Assignment 2025
Upcoming answers are provided in Telegram faster
Join us on Telegram 👉 CLICK HERE Â
NPTEL Joy Of Computing Using Python Week 12 Programming Assignment 2025
In this the following topics are discussed which are most important to the exam:
- Page Ranking
- Graphs
- Nodes
- Collatz Conjecture
Last Date: 17-04-2025
Q1. Given a sorted list nums in non-decreasing order, where every element appears twice except for one unique element, find and return the single number.
Example 1:
Input
nums = [1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6]
Output
4
Example 2 :
InputÂ
nums = [1, 1, 3, 5, 5]
Output
3
Constraints:
n==len(nums)
1<=n<=104
Program Code:
def singleNonDuplicate(nums):  result = 0  for num in nums:    result ^= num  return result {codeBox}
Q2. You are given a string s consisting of only lowercase English letters. Your task is to return a list of unique characters from the string, sorted in descending order based on their frequency of occurrence.
- If two or more characters have the same frequency, they should be sorted in alphabetical order.
Input:
- A string s
- The string consists of only lowercase English characters ('a' to 'z').
Output:
- A list of unique characters sorted by frequency (highest to lowest).
- If characters have the same frequency, they should appear in alphabetical order.
Example 1:
Input: s = "tree"
Output: ['e', 'r', 't']
Example 2 :
Input: s = "bbccddaaa"
Output: ['a', 'b', 'c', 'd']
Explanation:
The frequency of each character:
- 'a' → 3
- 'b' → 2
- 'c' → 2
- 'd' → 2
Since 'b', 'c', and 'd' have the same frequency, they are sorted alphabetically.
Program Code:
from collections import Counterdef frequencySort(s):Â Â freq = Counter(s)Â ÂÂ Â return sorted(freq, key=lambda x: (-freq[x], x))Â {codeBox}
Q3. Write a Python function subsequence(l1,l2) that takes two sorted lists as arguments and returns True if the the first list is a subsequence of the second list, and returns False otherwise.
A subsequence of a list is obtained by dropping some values. Thus, [2,3,4] and [2,2,5] are subsequences of [2,2,3,4,5], but [2,4,4] and [2,4,3] are not.
For Example :Â
Input:Â subsequence([2,2,5],[2,2,3,4,5])
Output: TrueÂ
Program Code:
def subsequence(l1, l2):Â Â i, j = 0, 0Â ÂÂ Â ÂÂ Â while i < len(l1) and j < len(l2):Â Â Â Â if l1[i] == l2[j]:Â ÂÂ Â Â Â Â Â i += 1Â Â Â Â j += 1Â ÂÂ Â ÂÂ Â return i == len(l1)Â {codeBox}
Conclusion
If you get any error in the code or are unable to paste join us in telegram and we solve your doubts