NPTEL » The Joy of Computing using Python
Please scroll down for latest Programs 👇
Week 2 - Programming Assignment 1
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 1 | 1 | 1\n
| Passed after ignoring Presentation Error |
Test Case 2 | 2 | 1 | 1\n
| Passed after ignoring Presentation Error |
Test Case 3 | 10 | 25 | 25\n
| Passed after ignoring Presentation Error |
Week 2 - Programming Assignment 2
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 0 | Neon Number | Neon Number\n
| Passed after ignoring Presentation Error |
Test Case 2 | 1 | Neon Number | Neon Number\n
| Passed after ignoring Presentation Error |
Test Case 3 | 2 | Not Neon Number | Not Neon Number\n
| Passed after ignoring Presentation Error |
Week 2 - Programming Assignment 3
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | hello | 2 | 2\n
| Passed after ignoring Presentation Error |
Test Case 2 | PYTHON | 1 | 1\n
| Passed after ignoring Presentation Error |
Test Case 3 | OpenAI 123 | 4 | 4\n
| Passed after ignoring Presentation Error |
Week 6 Programming Assignment : 1
Problem: Robot Arithmetic Module – Engineering Constraint
At RoboCore Labs, engineers are developing an embedded system for a low-power educational robot.
Due to hardware limitations, the robot’s control unit cannot use the built-in multiplication operation.
As a member of the firmware team, your task is to implement a function that computes the product of two positive integers without using the *
operator.
Requirements:
Function Name:
multiply
Parameters:
a
(positive integer)b
(positive integer)
Constraints:
You may only use the
+
(addition) and-
(subtraction) operators.The
*
(multiplication) operator is strictly forbidden.
Return Value:
The function should return the product of
a
andb
.
Implementation:
The solution must be implemented using recursion.
Note:
Do not read input from the user.
Do not print output to the console.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
3 | 6 | 6\n
| Passed after ignoring Presentation Error |
Test Case 2 | 5
4 | 20 | 20\n
| Passed after ignoring Presentation Error |
Test Case 3 | 10
17 | 170 | 170\n
| Passed after ignoring Presentation Error |
Test Case 4 | 23
4 | 92 | 92\n
| Passed after ignoring Presentation Error |
Test Case 5 | 100
1 | 100 | 100\n
| Passed after ignoring Presentation Error |
Week 6 Programming Assignment : 2
Problem: Searching Patient Records in a Health Analytics System
The hospital network MedNexus maintains a centralized database of patient record IDs.
These IDs are stored in sorted order to enable fast lookups.
You are part of the software development team tasked with optimizing the search functionality.
Since the system follows a recursive design pattern, you must implement a recursive version of the search algorithm to determine whether a given patient ID exists in the records.
Requirements
Function Name:
search
Parameters:
L
→ A sorted list of integers (patient record IDs).k
→ An integer representing the ID to search for.
Return Value:
Return
True
ifk
is present inL
.Return
False
ifk
is not present.
Constraints:
Must use recursion.
No need to accept input from the user.
No need to print output to the console. Only the function definition is required.
Example
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | search([1, 2, 3, 4], 2) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 2 | search([10, 20, 30, 40, 50], 15) | False | False\n
| Passed after ignoring Presentation Error |
Test Case 3 | search([-100, -10, 1, 10, 20, 30, 30, 40, 50], 31) | False | False\n
| Passed after ignoring Presentation Error |
Test Case 4 | search([-100, -10, 1, 10, 20, 30, 30, 40, 50], 50) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 5 | search([-100, -10, 1, 10, 20, 30, 30, 40, 50], -100) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 6 | search([-100, -10, 1, 10, 20, 30, 30, 40, 50], -200) | False | False\n
| Passed after ignoring Presentation Error |
Test Case 7 | search([10], 10) | True | True\n
| Passed after ignoring Presentation Error |
Week 6 : Programming Assignment 3
Problem: Signal Propagation in Network Simulation
At NeuroLink Systems, researchers are developing a simulation to analyze how signals propagate in a neural network grid.
The network is represented as a square matrix
A
, where each entry represents the connection strength between neurons.To study influence over multiple steps, the team must compute the matrix raised to a power
m
.Each matrix multiplication represents one time step of propagation.
Your task is to implement a recursive function to compute the power of a matrix.
Requirements
Function Name:
power
Parameters:
A
: A square matrix (2D list of integers or floats).m
: A positive integer (exponent).
Return Value:
The matrix
A^m
, computed recursively.
Constraints:
Must use recursion.
No user input or console printing — only function definition required.
Example
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3
3
1,2,3
4,5,6
7,8,9 | 468,576,684\n
1062,1305,1548\n
1656,2034,2412 | 468,576,684\n
1062,1305,1548\n
1656,2034,2412\n
| Passed after ignoring Presentation Error |
Test Case 2 | 3
2
1,2,3
4,5,6
7,8,10 | 30,36,45\n
66,81,102\n
109,134,169 | 30,36,45\n
66,81,102\n
109,134,169\n
| Passed after ignoring Presentation Error |
Test Case 3 | 3
4
1,0,0
0,1,0
0,0,1 | 1,0,0\n
0,1,0\n
0,0,1 | 1,0,0\n
0,1,0\n
0,0,1\n
| Passed after ignoring Presentation Error |
Test Case 4 | 4
3
1,2,3,4
5,6,7,8
9,10,11,12
13,14,15,16 | 3140,3560,3980,4400\n
7268,8232,9196,10160\n
11396,12904,14412,15920\n
15524,17576,19628,21680 | 3140,3560,3980,4400\n
7268,8232,9196,10160\n
11396,12904,14412,15920\n
15524,17576,19628,21680\n
| Passed after ignoring Presentation Error |
Week 7 : Programming Assignment 1
Problem 1: Image Noise Isolation in Data Analysis
At a medical research lab, image preprocessing involves working with square matrices that represent pixel intensity grids extracted from medical images.
Sometimes, due to faulty sensor data, certain rows and columns must be eliminated to isolate sub-regions of the matrix.
Your task is to implement a function that removes a specified row and column from a square matrix to produce a minor matrix.
Requirements
Function Name:
minor_matrix
Parameters:
M
: A square matrix (list of lists).i
: Index of the row to remove (0-based).j
: Index of the column to remove (0-based).
Return Value:
A new matrix with the
i
-th row andj
-th column removed.
Constraints:
The matrix
M
is always square (n × n
).M
has at least 3 rows and columns.Indexing is zero-based.
No input/output required — just define the function.
Example
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3
1,2,3
4,5,6
7,8,9
0
1 | 4,6\n
7,9 | 4,6\n
7,9\n
| Passed after ignoring Presentation Error |
Test Case 2 | 3
1,2,3
4,5,6
7,8,9
2
0 | 2,3\n
5,6 | 2,3\n
5,6\n
| Passed after ignoring Presentation Error |
Test Case 3 | 3
1,2,3
1,2,3
1,2,3
0
0 | 2,3\n
2,3 | 2,3\n
2,3\n
| Passed after ignoring Presentation Error |
Test Case 4 | 4
1,2,3,1
2,10,20,4
43,19,98,100
19,48,49,1
2
3 | 1,2,3\n
2,10,20\n
19,48,49 | 1,2,3\n
2,10,20\n
19,48,49\n
| Passed after ignoring Presentation Error |
Week 7 : Programming Assignment 2
Problem: Generating the IPL Points Table
You are part of the analytics team at the Indian Premier League (IPL) headquarters.
This year, a special edition of the tournament was organized as a round-robin event where each team played exactly one match against every other team. There were no ties — every match resulted in a clear winner and loser.
Eight teams participated in this format:
CSK, DC, KKR, MI, PK, RR, RCB, SH
The tournament officials recorded match outcomes in a specific format. For each team (in a fixed order), they listed the names of the teams it defeated. The lines follow this order:
CSK, DC, KKR, MI, PK, RR, RCB, SH
Example:
indicates that CSK won against MI, DC, and PK, and lost its remaining matches.
If a line only contains the team’s name (e.g., RCB
), it means that team lost all its matches.
Your Task
(a) Process the 8 lines of input and compute the total number of matches won by each team.
(b) Prepare the final IPL points table in descending order of number of wins.
(c) If two or more teams have the same number of wins, sort them in alphabetical order.
(d) Print each entry in the format:
with no spaces and one entry per line.
Constraints
Input always follows the described format.
Every team plays exactly 7 matches.
No drawn or tied games.
Example Input
Example Output
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | CSK,DC,KKR,MI,PK,RR,RCB,SH
DC,KKR,MI,PK,RR,RCB,SH
KKR,MI,PK,RR,RCB,SH
MI,PK,RR,RCB,SH
PK,RR,RCB,SH
RR,RCB,SH
RCB,SH
SH | CSK:7\n
DC:6\n
KKR:5\n
MI:4\n
PK:3\n
RR:2\n
RCB:1\n
SH:0 | CSK:7\n
DC:6\n
KKR:5\n
MI:4\n
PK:3\n
RR:2\n
RCB:1\n
SH:0\n
| Passed after ignoring Presentation Error |
Test Case 2 | CSK,DC,MI,PK
DC,RR,RCB,SH
KKR,CSK,DC,RR,MI
MI,DC,RCB,RR
PK,DC,KKR,MI,RCB
RR,CSK,PK,SH
RCB,CSK,KKR,RR
SH,CSK,KKR,MI,PK,RCB | SH:5\n
KKR:4\n
PK:4\n
CSK:3\n
DC:3\n
MI:3\n
RCB:3\n
RR:3 | SH:5\n
KKR:4\n
PK:4\n
CSK:3\n
DC:3\n
MI:3\n
RCB:3\n
RR:3\n
| Passed after ignoring Presentation Error |
Test Case 3 | CSK,RCB,MI,KKR
DC,CSK,KKR,MI,SH
KKR,PK,RR,RCB,SH
MI,KKR,PK,RR,SH,RCB
PK,CSK,DC,RCB
RR,CSK,DC,PK,SH
RCB,DC,RR
SH,CSK,PK,RCB | MI:5\n
DC:4\n
KKR:4\n
RR:4\n
CSK:3\n
PK:3\n
SH:3\n
RCB:2 | MI:5\n
DC:4\n
KKR:4\n
RR:4\n
CSK:3\n
PK:3\n
SH:3\n
RCB:2\n
| Passed after ignoring Presentation Error |
Test Case 4 | CSK
DC,CSK,KKR,MI,PK,RR,RCB,SH
KKR,CSK,MI,PK
MI,CSK,PK,RR,SH,RCB
PK,CSK,RCB,SH
RR,CSK,KKR,PK
RCB,CSK,KKR,RR,SH
SH,CSK,KKR,RR | DC:7\n
MI:5\n
RCB:4\n
KKR:3\n
PK:3\n
RR:3\n
SH:3\n
CSK:0 | DC:7\n
MI:5\n
RCB:4\n
KKR:3\n
PK:3\n
RR:3\n
SH:3\n
CSK:0\n
| Passed after ignoring Presentation Error |
Test Case 5 | CSK,SH,RCB
DC,CSK,SH
KKR,CSK,DC
MI,CSK,DC,KKR
PK,CSK,DC,KKR,MI
RR,CSK,DC,KKR,MI,PK
RCB,DC,KKR,MI,PK,RR
SH,KKR,MI,PK,RR,RCB | RCB:5\n
RR:5\n
SH:5\n
PK:4\n
MI:3\n
CSK:2\n
DC:2\n
KKR:2 | RCB:5\n
RR:5\n
SH:5\n
PK:4\n
MI:3\n
CSK:2\n
DC:2\n
KKR:2\n
| Passed after ignoring Presentation Error |
Week 7 : Programming Assignment 3
Problem Statement: Symmetric Double Pyramid Pattern
Objective:
Write a program to print a symmetric star pattern based on a given integer input n
.
Input:
A single integer
n
(1 ≤ n ≤ 100), representing the number of rows in the upper half of the pattern.
Output:
Print a pattern consisting of
2n - 1
rows.Each row should contain stars and spaces arranged symmetrically according to the value of
n
.
Example:
Input:
Output:
* * ** ** *** *** ******** *** *** ** ** * *
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4 | * *\n
** **\n
*** ***\n
********\n
*** ***\n
** **\n
* * | * *\n
** **\n
*** ***\n
********\n
*** ***\n
** **\n
* *\n
| Passed after ignoring Presentation Error |
Test Case 2 | 2 | * *\n
****\n
* * | * *\n
****\n
* *\n
| Passed after ignoring Presentation Error |
Test Case 3 | 3 | * *\n
** **\n
******\n
** **\n
* * | * *\n
** **\n
******\n
** **\n
* *\n
| Passed after ignoring Presentation Error |
Week 8: Programming Assignment 1
Problem Statement
You have a locker containing a number of coins. Each coin has a positive integer value engraved on it, representing its worth. You are required to determine whether it is possible to withdraw a subset of these coins such that their combined value is exactly equal to a target amount.
Function Specification
Write a recursive function named subset_sum
that takes the following arguments:
L
– a list of positive integers, where each integer represents the value of a coin.s
– a positive integer representing the target value.
The function should return True
if it is possible to choose a subset of coins from the list whose sum is exactly s
, and False
otherwise.
Constraints
The list
L
may be empty.No loops or libraries that generate all subsets may be used.
The solution must be recursive.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | subset_sum([2, 4, 6], 6) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 2 | subset_sum([1, 3, 5, 7], 10) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 3 | subset_sum([5, 10, 12], 3) | False | False\n
| Passed after ignoring Presentation Error |
Test Case 4 | subset_sum([], 0) | True | True\n
| Passed after ignoring Presentation Error |
Week 8: Programming Assignment 2
f(n) = 3n + 1 , if n is odd
We repeatedly apply the function f
starting from an integer n
, producing a sequence:
f(n), f(f(n)), f(f(f(n))), . . .
It is believed (but not proven) that no matter which positive number you start with, this sequence will always eventually reach 1.
Example:
If n = 10
, the sequence is:
Starting at n = 10
, we must apply the function f
six times to reach 1.
Your Task
Write a recursive function named collatz
that:
Accepts a positive integer
n
such that:1 < n ≤ 32,000
Returns the number of times the function
f
needs to be applied to reach 1.
Requirements
Do not print anything or take input from the user.
Only write the function definition.
Use recursion in your solution.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | collatz(10) | 6 | 6\n
| Passed after ignoring Presentation Error |
Test Case 2 | collatz(1) | 0 | 0\n
| Passed after ignoring Presentation Error |
Test Case 3 | collatz(3) | 7 | 7\n
| Passed after ignoring Presentation Error |
Test Case 4 | collatz(6) | 8 | 8\n
| Passed after ignoring Presentation Error |
Week 8: Programming Assignment 3
Problem: Twin Primes
Two numbers p and q are said to be twin primes if:
Both p and q are prime numbers, and
The absolute difference between them is 2, i.e.,
|p − q| = 2
.
Task
Write a function twin_primes(p, q)
that:
Accepts two integers
p
andq
as arguments,Returns
True
if they are twin primes, andFalse
otherwise.
Note:
The function should not print anything.
The function should not accept input from the user.You may use helper functions if needed.
- You only need to write the function definition. .
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | twin_primes(5, 7) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 2 | twin_primes(11, 13) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 3 | twin_primes(17, 19) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 4 | twin_primes(5, 6) | False | False\n
| Passed after ignoring Presentation Error |
Week 9 : Programming Assignment 1
Problem Statement: Merge Two Dictionaries
Write a function named merge
that merges two dictionaries D1
and D2
into a new dictionary D
following these rules:
Each key-value pair in
D
must come from eitherD1
orD2
.Every key from both
D1
andD2
must be present inD
.If a key appears in both
D1
andD2
, the value to retain depends on the argumentpriority
:If
priority
is"first"
, retain the value fromD1
.If
priority
is"second"
, retain the value fromD2
.
All keys in the resulting dictionary
D
must be sorted in alphabetical order.
Constraints:
Do not print anything.
Do not accept input from the user. Only define the function.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | merge({'a': 1, 'b': 2}, {'b': 3, 'c': 4}, "first") | {'a': 1, 'b': 2, 'c': 4} | {'a': 1, 'b': 2, 'c': 4}\n
| Passed after ignoring Presentation Error |
Test Case 2 | merge({'x': 10}, {'x': 20, 'y': 30}, "second") | {'x': 20, 'y': 30} | {'x': 20, 'y': 30}\n
| Passed after ignoring Presentation Error |
Test Case 3 | merge({'k': 5, 'm': 6}, {'n': 7, 'm': 8}, "first") | {'k': 5, 'm': 6, 'n': 7} | {'k': 5, 'm': 6, 'n': 7}\n
| Passed after ignoring Presentation Error |
Test Case 4 | merge({'p': 1}, {'q': 2}, "second") | {'p': 1, 'q': 2} | {'p': 1, 'q': 2}\n
| Passed after ignoring Presentation Error |
Week 9 : Programming Assignment 2
Problem Statement
You are given a 2-dimensional list mat
that represents a matrix.
Write a function rotate(mat)
that returns a new matrix rotated 90° clockwise.
The input
mat
is a list of lists, where each inner list represents a row.You do not need to handle input/output.
Hint / Approach:
First, compute the transpose of the matrix.
Then, reverse each row of the transposed matrix.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | [[1,2,3],[4,5,6]] | [[4, 1], [5, 2], [6, 3]] | [[4, 1], [5, 2], [6, 3]]\n
| Passed after ignoring Presentation Error |
Test Case 2 | [[7,8],[9,10],[11,12]] | [[11, 9, 7], [12, 10, 8]] | [[11, 9, 7], [12, 10, 8]]\n
| Passed after ignoring Presentation Error |
Test Case 3 | [[1]] | [[1]] | [[1]]\n
| Passed after ignoring Presentation Error |
Test Case 4 | [[1,2],[3,4]] | [[3, 1], [4, 2]] | [[3, 1], [4, 2]]\n
| Passed after ignoring Presentation Error |
Week 9 : Programming Assignment 3
Problem Statement
You are working on a text analysis tool that groups words based on their frequency in a given list. For example, you might want to find all words that appear exactly once, all words that appear twice, and so on.
Write a function freq_to_words
that accepts a list of lowercase words as input and returns a dictionary with the following structure:
Key: Frequency (positive integer) of the words
Value: List of all words that occur exactly that many times in the input
You do not need to accept any input from the user or print anything to the console. Just write the function definition.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | ['a', 'random', 'collection', 'a', 'another', 'a', 'random'] | {3: ['a'], 2: ['random'], 1: ['collection', 'another']} | {3: ['a'], 2: ['random'], 1: ['collection', 'another']}\n
| Passed after ignoring Presentation Error |
Test Case 2 | ['one', 'two', 'three', 'one'] | {2: ['one'], 1: ['two', 'three']} | {2: ['one'], 1: ['two', 'three']}\n
| Passed after ignoring Presentation Error |
Test Case 3 | ['x', 'x', 'y', 'z', 'y', 'x'] | {3: ['x'], 2: ['y'], 1: ['z']} | {3: ['x'], 2: ['y'], 1: ['z']}\n
| Passed after ignoring Presentation Error |
Test Case 4 | ['apple'] | {1: ['apple']} | {1: ['apple']}\n
| Passed after ignoring Presentation Error |
Week 10 : Programming Assignment 1
Problem Statement
You are working with a dataset named scores_dataset
, which is a list of dictionaries.
Each dictionary contains information about a student’s name, gender, city, and their scores in various subjects.
Example entry:
Two students X and Y are said to be in a mentorship relation in a given subject if:
That is, student X can mentor student Y in a subject if their score difference lies between 10 and 20 (inclusive) and X’s score is higher.
Constraints:
A student cannot mentor themselves.
If a student cannot mentor anyone, the list should be empty.
Function Signature
Write a function named mentors
that accepts:
scores_dataset
: a list of student recordssubject
: a string representing the subject
The function should return a dictionary:
Key:
SeqNo
of a studentValue: List of
SeqNo
values of students that can be mentored by this student in the given subject
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | [{'SeqNo': 1, 'Name': 'A', 'Mathematics': 90}, {'SeqNo': 2, 'Name': 'B', 'Mathematics': 80}, {'SeqNo': 3, 'Name': 'C', 'Mathematics': 70}, {'SeqNo': 4, 'Name': 'D', 'Mathematics': 75}, {'SeqNo': 5, 'Name': 'E', 'Mathematics': 60}]
Mathematics | {1: [2, 3, 4], 2: [3, 5], 3: [5], 4: [5], 5: []} | {1: [2, 3, 4], 2: [3, 5], 3: [5], 4: [5], 5: []}\n
| Passed after ignoring Presentation Error |
Test Case 2 | [{'SeqNo': 1, 'Name': 'A', 'Physics': 95}, {'SeqNo': 2, 'Name': 'B', 'Physics': 85}, {'SeqNo': 3, 'Name': 'C', 'Physics': 65}]
Physics | {1: [2], 2: [3], 3: []} | {1: [2], 2: [3], 3: []}\n
| Passed after ignoring Presentation Error |
Test Case 3 | [{'SeqNo': 1, 'Name': 'A', 'Biology': 92}, {'SeqNo': 2, 'Name': 'B', 'Biology': 81}, {'SeqNo': 3, 'Name': 'C', 'Biology': 72}, {'SeqNo': 4, 'Name': 'D', 'Biology': 62}]
Biology | {1: [2, 3], 2: [4], 3: [4], 4: []} | {1: [2, 3], 2: [4], 3: [4], 4: []}\n
| Passed after ignoring Presentation Error |
Week 10 : Programming Assignment 2
IIT Ropar has a campus store called RoparMart. Each transaction is recorded as a dictionary with:
"TID"
: Unique transaction ID (string)"Items"
: List of dictionaries for each item with:"Name"
: Name of the item"Price"
: Price per unit"Qty"
: Quantity purchased
Task: Write a function get_summary(trans)
that computes the total cost of each transaction and returns a summary list.
Function Signature:
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | [{"TID": "RoparMart_1001", "Items": [{"Name": "Notebook", "Price": 50, "Qty": 4}, {"Name": "Pencil", "Price": 10, "Qty": 1}, {"Name": "Eraser", "Price": 15, "Qty": 1}, {"Name": "File", "Price": 80, "Qty": 1}]}] | [{'TID': 'RoparMart_1001', 'Cost': 305}] | [{'TID': 'RoparMart_1001', 'Cost': 305}]\n
| Passed after ignoring Presentation Error |
Test Case 2 | [{"TID": "RoparMart_1002", "Items": [{"Name": "Pen", "Price": 20, "Qty": 2}, {"Name": "Scale", "Price": 30, "Qty": 1}]}] | [{'TID': 'RoparMart_1002', 'Cost': 70}] | [{'TID': 'RoparMart_1002', 'Cost': 70}]\n
| Passed after ignoring Presentation Error |
Week 10 : Programming Assignment 3
Problem Statement: Run-Length Encoding for Hostel Notice Board
The hostel manager at IIT Ropar maintains a digital notice board accessible to all students. Notices are uploaded as plain text, but as the number of notices grows, server space usage increases.
To reduce storage, the IT admin wants a basic compression algorithm that can shrink repetitive characters in each notice.
Compression Logic
The admin proposes using a simple form of Run-Length Encoding (RLE):
Consecutive repetitions of a character are replaced with the character followed by the count of its occurrences.
If a character appears only once consecutively, it remains unchanged.
Example:
Task
Write a function compress
that accepts a string notice
and returns its compressed form using the above RLE logic.
Function Signature:
Instructions
You do not need to accept input from the user or print output to the console.
All characters in the string will be lowercase letters.
The length of the string will be between 1 and 1000.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | " aaabccddddee " | a3bc2d4e2 | a3bc2d4e2\n
| Passed after ignoring Presentation Error |
Test Case 2 | " abc " | abc | abc\n
| Passed after ignoring Presentation Error |
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.