Cpro Assignment 3
Cpro Assignment 3
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. Think why?
1.3 Examples
Example 1:
• Input:
1 1
2 3
• Output: 6
Example 2:
• Input:
1
3 3
123 456
• Output: 56088
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
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
and i-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. Also, calculate the i-index, i-index is the number of publications with at least 10
citations.
You are required to calculate both the h-index and i-index, using pointers and
dynamic memory allocation in C.
2.1 Examples
Example 1:
• Input:
5
0 1 3 5 6
• Output: 3 0
• 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. There is no paper with
10 citations or more so the i-index is 0.
Example 2:
• Input:
3
1 2 100
• Output: 2 1
3
2.3 Output Format
• An integer representing the researcher’s h-index & i-index.
2.4 Constraints
• n == citations.length
• 1 ≤ n ≤ 105
• 0 ≤ citations[i] ≤ 1000
4
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
Details for implementing Jagged Array:
• Please note that the number of rows will be fixed for the jagged array.
– Operation 1: Append a given value val to the end in the ith row.
– Operation 2: Print the entire row.
– 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.
4 8
2 2
1 2 4
2 2
5
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 (operation) 2 (row). The second row should be printed. The
matrix will remain unchanged.
2. After the second query 1 (operation) 2 (row) 4 (val), 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. 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
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 for arrays in this problem in any form will result in
a straight 0 for the entire assignment. You have to use malloc, calloc and
realloc to do this problem.
• The size of each row should be equal to number of elements inserted. You should not
allocate extra memory for any row, doing so will also result in a straight 0 for the entire
assignment.