NPTEL Joy Of Computing Using Python Week 10 Programming Assignment 2025

Hey Folks, This article featured NPTEL Joy Of Computing Using Python Week 10 Programming Assignment 2025. Answers for the Week 9 programming are provided below. All Programming questions are passed with 100% test cases. 

Also Read: NPTEL Joy Of Computing Using Python Week 9 Programming Assignment 2025

Upcoming answers are provided in Telegram faster
Join us on Telegram 👉 CLICK HERE  

NPTEL Joy Of Computing Using Python Week 10 Programming Assignment 2025


NPTEL Joy Of Computing Using Python Week 10 Programming Assignment 2025

In this Week 10, the following topics are discussed: 
  • FLAMES
  • Data Compression 
Last Date: 03-04-2025

Q1. Emma is a budding software developer working on a signal detection system. One day, her mentor gives her a special list called nums. This list only contains two types of signals:
1 represents a strong signal.
0 represents a weak signal.

Emma's task is to find out the longest streak of consecutive strong signals (1s) in the list, which will help her identify the best time period for stable communication.
Can you help Emma write a Python function that takes the list nums as input and returns the maximum number of consecutive strong signals in the list?

Program Code: 

def findMaxConsecutiveOnes(nums):
    max_streak = 0
    current_streak = 0
    
    for num in nums:
        if num == 1:
            current_streak += 1
            max_streak = max(max_streak, current_streak)
        else:
            current_streak = 0  
            
    return max_streak {codeBox}


Q2. In the ancient land of Lexiconia, hidden messages are locked behind a common magical prefix. Only those who can decipher the longest common prefix will unveil the wisdom of the lost texts.

Your task is to create a function that accepts a list of words, finds the longest common prefix, and prints the result.

Write a function longest_common_prefix(st) that:
  • Accepts a list of strings as input.
  • Returns the longest common prefix among all the strings.
  • If there is no common prefix, return an empty string "".

Program Code: 

import ast
def longestCommonPrefix(st):
    if not st:
        return ""
    prefix = st[0]
    for word in st[1:]:
        while not word.startswith(prefix):
            prefix = prefix[:-1]
            if not prefix:
                return ""
    return prefix
  
input_list = ast.literal_eval(input().strip())
print(f'"{longestCommonPrefix(input_list)}"', end='') {codeBox}


Q3.Once upon a time in the land of Isomorphia, there were two ancient scrolls written in different languages. The wise king of Isomorphia wanted to know if these scrolls conveyed the same message or if they were completely different. He summoned his greatest coder, who had the magical power of Isomorphic Translation.

The challenge was to determine if every symbol in the first scroll could be mapped to exactly one symbol in the second scroll, without any two symbols sharing the same mapping. However, the order of symbols in both scrolls had to be preserved.

The coder had to write a function to check if the two scrolls were isomorphic or not.

Examples:
Input : s = "egg" , t = "add"
Output : true
Explanation : The 'e' in string s can be replaced with 'a' of string t.
The 'g' in string s can be replaced with 'd' of t.
Hence all characters in s can be replaced to get t.

Input : s = "apple" , t = "bbnbm"
Output : false
Explanation : One possible try can be:

The 'a' in string s can be replaced with 'n' of string t.
The 'p' in string s can be replaced by 'b' of string t.
The 'l' in string s can be replaced by 'm' of string t.
The 'e' in string s cannot be replaced by any character of string t as all the characters in string t are already mapped.
Hence all characters in s cannot be replaced to get t by this try. It can be proved that no solution exists for this example.

Program Code: 

def isIsomorphic(s, t):
    mapping = set(zip(s, t))
    return len(mapping) == len(set(s)) == len(set(t))


s = input().strip()
t = input().strip()
print(isIsomorphic(s, t), end='') {codeBox}

Conclusion:

If you get any error in the code or are unable to paste join us in telegram and we solve your doubts

Join us on Telegram 👉 CLICK HERE


One Comment Please !

Post a Comment (0)
Previous Post Next Post