C Programming Assigment IIITH
C Programming Assigment IIITH
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.3 Examples
Example 1:
• Input: 1 1 2 3
• Output: 6
Example 2:
• Output: 56088
1
1.4 Constraints
• 0 ≤ num1.length, num2.length ≤ 500
• 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:
• Output: 2
2
2.4 Constraints
• n == citations.length
• 1 ≤ n ≤ 105
• 0 ≤ citations[i] ≤ 1000
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.
– 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
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
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.