0% found this document useful (0 votes)
8 views

C Programming Assigment IIITH

Uploaded by

Arza Siddiqui
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

C Programming Assigment IIITH

Uploaded by

Arza Siddiqui
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CPro-Assignment 3

Devesh Marwah
Computer Programming, Monsoon 2024
Deadline: 18th September, 2024. 11:59 PM

1 Dr Doofenshmirtz
Phineas and Ferb have designed a high-tech calculator. However their sister Candance wants
to show them wrong and has come up with two numbers num1 and num2 that they need to
multiply. However, to make things more interesting, they’ve represented these numbers
as strings rather than regular integers. The challenge is to find the product of these two
numbers and display it as a string, just like how they like to do things in their imaginative
world.
Formally, Given two non-negative integers num1 and num2 represented as strings, return
their product as a string.
Note: You must not convert the inputs to integer directly.

1.1 Input Format


Lengths of the two non-negative integers L1 L2 num1 and num2, each represented as strings.

1.2 Output Format


A string representing the product of num1 and num2.

1.3 Examples
Example 1:

• Input: 1 1 2 3

• Output: 6

Example 2:

• Input: 3 3 123 456

• Output: 56088

1
1.4 Constraints
• 0 ≤ num1.length, num2.length ≤ 500

• num1 and num2 consist of digits only.

• Both num1 and num2 do not contain any leading zero, except the number 0 itself.

2 Breaking Enigma
Professor Turing, a brilliant computer scientist, has published many influential research
papers. To measure his academic impact, Professor Turing wants to calculate his h-index,
a metric that reflects both the number of papers he has published and how often they are
cited.
Formally, The h-index is defined as the largest number h such that the professor has
published at least h papers, each cited h times or more. Given the citation data, which is
sorted in ascending order help Professor Turing determine his h-index using an efficient
algorithm.

2.1 Examples
Example 1:

• Input: 5 0 1 3 5 6

• Output: 3

• Explanation: 5 is the length of the array. [0, 1, 3, 5, 6] means the researcher has
5 papers in total and each of them had received 0, 1, 3, 5, and 6 citations, respectively.
Since the researcher has 3 papers with at least 3 citations each and the remaining two
papers have no more than 3 citations each, their h-index is 3.

Example 2:

• Input: citations = 3 1 2 100

• Output: 2

2.2 Input Format


• An array of integers citations where each element represents the number of citations
for the corresponding paper.

2.3 Output Format


• An integer representing the researcher’s h-index.

2
2.4 Constraints
• n == citations.length

• 1 ≤ n ≤ 105

• 0 ≤ citations[i] ≤ 1000

• citations is sorted in ascending order.

3 Jagged Arrays
Jagged arrays, also known as ”ragged arrays” are a type of multidimensional array where
the inner arrays can have different lengths.
For example in the following 2D array, you can observe each row has a different length.
Your task for the problem is to implement a 2-D jagged array in C by allocating memory
dynamically.
 
1
4 5 6
7 8
Initially you will be given number of rows (r) and assume it is r x 1 matrix filled with
value 1. Please note that the number of rows will be fixed for the jagged array.

The jagged array should support the following 2 operations:

• Operation 1: Append a given value val in the ith row.

• Operation 2: Print the entire row.

For more clarity, refer to the example test cases.

3.1 Input format


• The first line contains a integer r (Number of rows) and t (Number of queries).

• For each query, the following 2 cases are possible:

– Operation 1: You will be given a row i such that 1 ≤ i ≤ r and value val.
– Operation 2: You will be given a row i such that 1 ≤ i ≤ r.

3.2 Output Format


Print the entire row if and when required

3
3.3 Sample Test Case
Input:

4 8
2 2
1 2 4
2 2
1 2 5
2 2
2 1
1 1 3
2 1

Output:

1
1 4
1 4 5
1
1 3

Explanation: Initially the matrix will be 4x1 matrix with each row having value 1
 
1
1
 
1
1

The following will be the state of the array at each query:

1. After the first query 2 2, the second row should be printed. The matrix will remain
unchanged.

2. After the second query 1 2 4, the second row would be updated and 4 should be
appended to the end of 2nd row. The new matrix is
 
1
1 4
 
1 
1

3. After the third query 2 2, the second row should be printed. The matrix will remain
unchanged.

4
4. After the fourth query 1 2 5, the second row would be updated and 5 should be
appended to the end of 2nd row. The new matrix is
 
1
1 4 5
 
1 
1

5. After the fifth query 2 2, the second row should be printed. The matrix will remain
unchanged.

6. After the sixth query 2 1, the first row should be printed. The matrix will remain
unchanged.

7. After the seventh query 1 1 3, the first row would be updated and 4 should be appended
to the end of first row. The new matrix is
 
1 3
1 4 5
 
1 
1

8. After the eigth query 2 1, the first row should be printed. The matrix will remain
unchanged.

3.4 Note
Using static memory in this problem any form will result in a straight 0 for the
entire assignment.

You might also like