Posts

SORT8

QUESTION DESCRIPTION  Given an array with all elements greater than or equal to zero.Return the maximum product of two numbers possible. Input: The first line of input contains an integer T denoting the number of test cases. The first line of each test case is N, N is size of array. The second line of each test case contains N input A[i]. Mandatory method for this program is "void sort(int a[],int n)" Output: Print the maximum product of two numbers possible. Constraints: 1 ≤ T ≤ 20 1 ≤ N ≤ 50 0 ≤ A[i] ≤ 1000 TEST CASE 1  INPUT 1 5 1 100 42 4 23 OUTPUT 4200 TEST CASE 2  INPUT 2 6 4 8 9 21 1 7 5 42 1 92 12 17 OUTPUT 189 3864 #include <iostream> using namespace std; int main() { int n,t,temp,i,j; cin>>n; cin>>t; int arr[t]; while(t--) { cin>>arr[t]; for(i=0;i<=t;i++) { for(j=i+1;j<=t;j++) { if(arr[i]>arr[j]) { temp=arr[i]; arr[i]=arr[j]; temp=arr[j...

SER4

QUESTION DESCRIPTION  the professor is conducting surprise test for Engineering first year students. he has dictated an array of n integers.all the elements in array is obtained by adding either +1 or -1 to previous element. Professor gave mandatory condition for this problem like the difference between any two consecutive elements is 1. The expected outcome of the problem is to search an element index with the minimum number of comparison (less than simple element by element search). If the element is present multiple time, then print the smallest index. If the element is not present print -1. TEST CASE 1  INPUT 8 5 4 5 6 5 4 3 2 4 OUTPUT 1 TEST CASE 2  INPUT 8 5 4 5 6 4 3 2 3 9 OUTPUT -1 #include <stdio.h> int main() { int n; scanf("%d",&n); int a[n],k,i,j,f=0,g; for(i=0;i<n;i++) { scanf("%d",&a[i]); } scanf("%d",&k); for(i=0;i<n;i++) { if(a[i]==k) { f=1; g=i; break; ...

SER11

QUESTION DESCRIPTION  Today, you have been given a task like ones back end developers face on a daily basis. You need to help in dealing with large amount of requests received in a purchasing application. The application has the following properties: Consumers place large number of orders via this application Each request has a time stamp and an order size associated with it. Each order size is considered in terms of kilo-grams and can be of integer weight only. Now, the data analytics team needs some information on regular intervals. Based on the requests received in the app, you need to help answer all queries posed by the data-analytics team. So, your task is: Given 2 2 types of queries, the first one being of the form 1 1 X X T T, indicates an order of weight X X is received at time T T. The second one is of the form 2 2 K K T T indicates that the data analytics team asks you about the summation of weight of the orders received during the last K K minutes at time T T. The fir...

SER9

World cup team squad annocunced for level one matches. There are a lot of Poke'mons who are jealous of the fact that they do NOT have any specialty, they're the... normal type of Poke'mon. But, what they fail to realize is that their power is their normalcy, the ability to think, rationalize and then act. But, they do have an additional power... Poke'mons like Jigglypuff - which are normal, can figure out if a trainer is real or is a part of Team Rocket. And they need to use their power to a great extent. In an array, which consists of N N elements, A1, A2, ..., AN, if a subarray has the total number of distinct elements as that of the original array, that determines the presence of Team Rocket. You've to help the normal type Poke'mons in figuring out the total number of subarrays having total number of distinct elements same as that of the original array. Input format: The first line of the input will consist of a single integer N N. The next line will consis...

SER12

QUESTION DESCRIPTION  There is a classroom which has M M rows of benches in it. Also, N N students will arrive one-by-one and take a seat. Every student has a preferred row number(rows are numbered 1 1 to M M and all rows have a maximum capacity K K. Now, the students come one by one starting from 1 1 to N N and follow these rules for seating arrangements: Every student will sit in his/her preferred row(if the row is not full). If the preferred row is fully occupied, the student will sit in the next vacant row. (Next row for N will be 1) If all the seats are occupied, the student will not be able to sit anywhere. Monk wants to know the total number of students who didn't get to sit in their preferred row. (This includes the students that did not get a seat at all) Mandatory to use loop condition as "while(x!=y)" Input First line contains 3 integers N N, M M and K K. N N - Number of students and M M - Number of rows and K K - maximum capacity of a row. Next line contains...

SER14

#include<stdio.h> void swap(long long int *a, long long int *b) {   long long int t;   t=*a;   *a=*b;   *b=t; } void qsort(long long int items[][4], long long int left, long long int right) {      register long long int i,j,k;      long long int x, y;            i = left; j = right;      x = items[(left+right)/2][3];      do       {         while((items[i][3] < x) && (i < right))             i++;         while((x < items[j][3]) && (j > left))            j--;         if(i <= j)          {              y = items[i][0];items[i][0] = items[j][0];items[j][0] = y; y = items[i][1];items[i][1] = items[j][1];items...

SER15

#include <stdio.h>     #include <math.h>           int main()     {         long int n,i,x,root,val,flag=0;         scanf("%ld",&n);         for(i=1;i<=100000;i++)         {             val=(i*(i+1))/2;             if(val>n/2)             break;             x=(n-val)*2;             root=sqrt(x);             if(x==(root*(root+1)))             {                 flag=1;                 break;             }         }         if(flag==1)         printf(...