The Joy of Computing using Python Week 5: Programming Assignment - Jun-Dec 2021

  

NPTEL PROGRAMMING ASSIGNMENTS

The Joy of Computing using Python


Week 5: Programming Assignment 1 - k times

Due on 2021-09-02, 23:59 IST

Given a list of integers and a value k, print the number in the list that appears exactly k times. (It is guaranteed that there’s exactly one integer that appears k times).

Input Format:

First line of the input contains a list of integers

Second line of the input contains a value k

Output Format:

Display the number that appears exactly k times

Example:

Input:

1 2 2 3 3 3

3

Output:

3

  

Week 5: Programming Assignment 2 - kth Largest

Due on 2021-09-02, 23:59 IST

Given a list of integers and a value k, print the kth largest element in the list. (All the elements in the list are guaranteed to be distinct).

Input Format:

First line of the input contains a list of integers

Second line of the input contains a value k

Output Format:

Display the kth largest element in the list

Example:

Input:

5 3 6 10 2

3

Output:

5

 

Week 5: Programming Assignment 3 - Cumulative sum

Due on 2021-09-02, 23:59 IST

Given a list of n integers, print a new list such that every element in the new list represents the cumulative sum of all the elements until that position.

Input Format:

Single line of input contains a list of space separated integers 

Output Format:

Print the cumulative list

Example:

Input:

1 2 3 4 5

Output:

1 3 6 10 15


  


2 Comments



  1. a=input().split()
    b=int(input())
    for i in range(len(a)):
    a[i]=int(a[i])
    a.sort(reverse=True)
    print(a[b-1],end='')

    Solution for the Kth largest assignment question is modified to make it work for all test cases.

    ReplyDelete
    Replies
    1. Thanks for reply, the answere is now modified just change b-1 to -b

      Delete
Post a Comment
Previous Post Next Post