Set 4 Assignment
Set 4 Assignment
SET 4:
1. Given an array of positive consecutive numbers, with some numbers missing. Write a
program to find those missing numbers.
Example:
find_missing([1, 2, 3, 4, 6, 8, 10]) → should return {5, 7, 9}
find_missing([88, 90, 91, 92, 93, 96, 97, 98, 100, 101]) → should return {89, 94, 95, 99}
2. class Program
3. {
4.
5. static void printMissingElements(int[] arr, int N)
6.
7. {
8.
9.
10. int diff = arr[0] - 0;
11.
12. for (int i = 0; i < N; i++)
13. {
14.
15. if (arr[i] - i != diff)
16. {
17.
18.
19. while (diff < arr[i] - i)
20. {
21. Console.Write(i + diff + " ");
22. diff++;
23. }
24. }
25. }
26. }
27.
28.
29. static void Main()
30. {
31.
32.
33. int[] arr1 = { 1, 2, 3, 4, 6, 8, 10 };
34.
35. int N1 = arr1.Length;
36.
37.
38. printMissingElements(arr1, N1);
39.
40. Console.WriteLine();
41.
42. int[] arr2 = { 88, 90, 91, 92, 93, 96, 97, 98, 100, 101 };
43.
44. int N2 = arr2.Length;
45.
46.
47. printMissingElements(arr2, N2);
48.
}}}
49. Console.ReadLine();
50. Find the smallest positive integer value that cannot be represented as sum of any subset of a
given array?
Examples:
1. Input: {1, 3, 6, 10, 11, 15};
Output: 2
2. Input: {1, 1, 1, 1};
Output: 5
3. Input: {1, 1, 3, 4};
Output: 10
4. Input: {1, 2, 5, 10, 20, 40};
Output: 4
class Program
{
static int findSmallest(int[] arr, int n)
{
int res = 1;
return res;
}
Console.ReadLine();
}
}