Monday, December 21, 2020

TEST -3 FOR CRT

 

Question – 1:

Mahirl is a little girl who loves to play. Today she is playing by moving some stones between two piles of stones. Initially, one of the piles has A and the other has B stones in it.

Mahirl has decided to perform a sequence of K operations. In each operation she will double the size of the currently smaller pile. Formally, if the current pile sizes are labeled X and Y in such a way that X <= Y, she will move X stones from the second pile to the first one. After this move the new pile sizes will be X+X and Y-X.

Given the ints AB, and write a program to determine the size of the smallest pile after Mahirl finishes all her operations.
 

Input and Output Format:

Input consists of 3 integers – A, B and K .

The first integer corresponds to A, the number of stones in the first pile.

The second integer corresponds to B, the number of stones in the second pile.

The third integer corresponds to K, the number of operations performed.
 

Output consists of an integer that corresponds to the size of the smallest pile.

 

Sample Input :

4

7

2

 

Sample Output :

5

1

t7

1
1
2000

0

2

t3

2
6
1

4

3

t2

5
5
3

0

4

t4

2
8
1

4

5

t10

231
5
10

 

 

Question – 2:

 

A man is doing a something experiment with the device that he built newly. The structure of the device is shown as below diagram



B to E is a sloping surface with n holes, labeled H1, H2, H3... Hn, on it. Holes are of different diameters & depths. The man is releasing m number of balls of different diameters from the point B one after the other. He wants to find the positions of each ball after the experiment.  The specialties of the device are as follow:

1.      A ball will fall into a hole, if and only if its diameter is less than or equal to the diameter of the hole. 

2.      A hole Hi will become Non-empty i.e Full, if i no. of balls fall into it. For ex hole labeled as H3 will become full if THREE balls fall into it.

3.      If a hole is full then no more balls can fall into that hole.

4.      A ball will reach the bottom point E from B, only if it is not falling into any 1 of the holes.

Please help him in finding the eventual position of the balls. If a ball is in hole Pi, then take its position as i. If a ball reached the bottom point E, then take its position as 0. 

Constraints

·                  0 < N <= 50

·                  0 < Diameter of holes <= 10^9

·                  0 < M <= 1000

·                  0 < M <= 1000

Input Format

Line 1: total number of holes, N

Line 2: N space separated integers denoting the diameters of N holes, from bottom to top

Line 3: total number of balls, M 

Line 4: M space separated integers denoting the diameters of balls in the order of release. 

Output 

Line 1: Positions of each ball in the order of ball release separated by space 

Explanation 

Input

3

21 3 6 

11 

20 15 5 7 10 4 2 1 3 6 8

Output

1 0 3 0 0 3 3 2 2 0 0

 

Sunday, December 6, 2020

ECE FINAL YR TT 2020


 1-D Array:

13.Longest palindrome in an array
14.Non-repeating elements of an array
15.Minimum scalar product of two vectors
16.Check if two arrays are the same or not
17.Sum range of elements in an array
18.Array is a subset of another array or not

2-D Arrays

19.Matrix operations (Addition, subtraction and multiplication)
20.Transpose of a matrix
21.Upper triangular matrix or not
22.The maximum element in a row
23.The maximum element in a column
24.Saddle point coordinates of a given matrix
25.Matrix printing in a spiral form
26.Matrix rotation by 90 degrees clockwise and anticlockwise
27.Maximum binary sum  of matrix row with all 1s in a binary matrix
28.Number of even and odd elements in an array
29Write a program in C to merge two arrays of same size sorted in descending order
30 Write a program in C to insert New value in the array (sorted list ).
31 Write a Program to Find the Sum of Contiguous Subarray within a 1 – D Array of Numbers which has the Largest Sum.
   If we are entering 8 elements (N = 8), with array element values as -1,-5,5,3,-2,5,4 and 1 then,
The largest contiguous subarray is: 5 3 -2 5 4 1
The sum of the largest contiguous subarray is: 16

32 Program to Split an Array from Specified Position & Add First Part to the End.
33 Program to identify missing Number in a given Array
34   Program to Segregate 0s on Left Side & 1s on right side of the Array
35 Program to Find 2 Elements in the Array such that Difference between them is Largest
36 Program to Find the two Elements such that their Sum is Closest to Zero
37  Program to Find if a given Integer X appears more than N/2 times in a Sorted Array of N Integers
38 Program to Find Ceiling & Floor of X given a Sorted Array & a value X
STRINGS
39.program that reads a string and find the frequency of character for case insensitive.
40.program to remove special character in the given string.
41.program to find longest word in the given string.
42.program to reverse each word in the given string.
43.program to find highest frequency character in string.
44.program to replace a substring in a given string.
 45.  Read a string which contains only lowercase alphabets and position. Find the character at given position and print the number of occurrence of same alphabet preceding the given position.
Sample Input:
abacsddaa
9
Sample Output:
3


46.Read an expression and remove parenthesis.
Sample Input
(A*B)+(C/D)-E
Sample Output
A*B+C/D-E

47.Read an expression and count number of valid parenthesis.
Sample Input
((A*B)+(C/D)-E)
Sample Output
3


48.Read an expression and check whether expression contains valid parenthesis or not.
Sample Input1
((A*B)+(C/D)-E)
Sample Output1
Valid
Sample Input2
((A*B)+(C/D-E)
Sample Output2
Invalid

 2-D Array's

49.Write a program to sort set of strings in alphabetical order.

50.Write a program to concatenate set of strings.

51.Write a program that find and print substring in set of strings. If no substring found print ‘NULL’.

52.Write a program to search for a string in set of strings.

53.Write a program that find and print same length strings in array of strings.
















Missing elements in range: 

// Print all elements of range [low, high] that
// are not present in arr[0..n-1]
void printMissing(int arr[], int n, int low,
                  int high)
{
    // Sort the array
    sort(arr, arr + n);
  
    // Do binary search for 'low' in sorted
    // array and find index of first element
    // which either equal to or greater than
    // low.
    int* ptr = lower_bound(arr, arr + n, low);
    int index = ptr - arr;
  
    // Start from the found index and linearly
    // search every range element x after this
    // index in arr[]
    int i = index, x = low;
    while (i < n && x <= high) {
        // If x doesn't math with current element
        // print it
        if (arr[i] != x)
            cout << x << " ";
  
        // If x matches, move to next element in arr[]
        else
            i++;
  
        // Move to next element in range [low, high]
        x++;
    }
  
    // Print range elements thar are greater than the
    // last element of sorted array.
    while (x <= high)
        cout << x++ << " ";
}
  
// Driver program
int main()
{
    int arr[] = { 1, 3, 5, 4 };
    int n = sizeof(arr) / sizeof(arr[0]);
    int low = 1, high = 10;
    printMissing(arr, n, low, high);
    return 0;
}


31 solution:
  1. int main()
  2. {
  3.     int size,m=0,l=0;
  4.  
  5.     printf("Type the length of the array\n");
  6.     scanf("%d",&size);
  7.     int array[size];
  8.     printf("type the elements of the array\n");
  9.  
  10.     for(int i=0;i<size;i++)
  11.     {
  12.         scanf("%d",&array[i]);
  13.  
  14.     }
  15.      int largest=array[0];
  16.     for(int i=0;i<size;i++)
  17.     {
  18.         int sum=0;
  19.         for(int j=i;j<size;j++)
  20.         {
  21.             sum=sum+array[j];
  22.             if(sum>largest)
  23.             {
  24.                 m=i;l=j;
  25.                 largest=sum;
  26.             }
  27.         }
  28.     }
  29.      printf("\n The largest contigous subarray is");
  30.     for(int z=m;z<=l;z++)
  31.     {
  32.         printf(" %d ",array[z]);
  33.     }
  34.     printf("\n The sum of the largest contigous subarray is");
  35.     printf(" %d",largest);
  36.     return 0;
  37. }

Program to identify missing Number in a given Array solution

/* getMissingNo takes array and size of array as arguments*/
int getMissingNo(int a[], int n)
{
    int i, total;
    total = (n + 1) * (n + 2) / 2;
    for (i = 0; i < n; i++)
        total -= a[i];
    return total;
}
 
/*program to test above function */
int main()
{
    int a[] = { 1, 2, 4, 5, 6 };
    int miss = getMissingNo(a, 5);
    printf("%d", miss);
    getchar();
}