Saturday, 8 July 2017

Odessa Technologies

Odessa Technologies-first round - 1
Given an array in unsorted order sort the array and sum the last two elements in the array and find the difference of first two elements in the array
then find the sum by difference

Sample input:1 2 3 4 5 6
Sample input:11

Note: The N (number of elements is not given)

 solution:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<limits.h>
#include<stdlib.h>

int main() {
    int arr[1000],sarr[1000],hash[1000]={0},l=0,i=0,j,k,max=INT_MIN;
    int start,end;
   
while(scanf("%d",&arr[i])==1)
    {
        hash[arr[i]]++;                            // The counts are stored in the hash table
        if(arr[i]>=max)
          {
            max = arr[i];              // The maximum values of the array is stored in the Max
          } 

    i++;

    }

    for(j=0;j<=max;j++)

    {

        if(hash[j])                           //To remove duplicates and print in sorted order

        {
             sarr[l]=j;
             l++;
        }

    }
    l--;

        end = sarr[l]+sarr[l-1];           // sum the last two index
        start = sarr[0]-sarr[1];           // diference the first two index
        start = abs(start);
        printf("%d",end/start);            //last two index sum / first two index difference
    return 0;

}




Odessa Technologies first round - 2 
To remove duplicate and print the array in the sorted order

the number of element N is not given (it is possible only in Online compiler)

sample Input: 1 2 1 2 1 2 1 2 1 2 4 3

Sample Output: 1 2 3 4


Solution:

#include<stdio.h>
#include<string.h>
#include<limits.h>
#include<stdlib.h>
int main() {int arr[1000],hash[1000]={0},l=0,i=0,j,max=INT_MIN;

while(scanf("%d",&arr[i])==1)
    {
        hash[arr[i]]++;                            // The counts are stored in the hash table
        if(arr[i]>=max)
          {
            max = arr[i];      // The maximum values of the array is stored in the Max
          }  
    i++;
    }
    for(j=0;j<=max;j++)
    {
        if(hash[j])                           //To remove duplicates and print in sorted order
        {
              printf("%d ",j);
        }
    }
    return 0;
}

No comments:

Post a Comment

Troubleshooting in SQL

1. SSRS Error  Round () need to be done in  SQL itself  2. Default Date In SSRS  Start Date =CDate(Format(DateAdd("d",-50,Now()), ...