Practice Questions & Answers :: Cocubes

Cocubes
Tot. Mock Test: 73+
Tot. Exam. Sec.: 5+
Total Practice Qs: 137+
51 / 137
Which of the following is not an application of sorted array?
AHash Tables
BCommercial computing
CPriority Scheduling
DDiscrete Mathematics
Answer: Option A
Explanation:Sorted arrays have widespread applications as all commercial computing involves large data which is very useful if it is sorted. It makes best use of locality of reference and data cache. Linked lists are used in Hash Tables not arrays.
Submit Your Solution
Tags: No Tags on this question yet!
52 / 137
What is the time required to locate the occurrences of a pattern P of length m in a string of length n using suffix array?
AO(mlogn)
BO(nm)
CO(n2)
DO(mnlogn)
Answer: Option A
Explanation:Suffix arrays are used to find the occurrences of a pattern in a string. Pattern of length m will require m characters to compare, so using suffix array we can find occurrences of a pattern in the string of length n in O(mlogn) time.
Submit Your Solution
Tags: No Tags on this question yet!
53 / 137
What does the number of inversions in an array indicate?
Amedian value of the elements of array
Bmean value of the elements of array
Cmeasure of how close or far the array is from being sorted
Dthe distribution of values in the array
Answer: Option C
Explanation:The number of inversions in an array indicates how close or far the array is from being completely sorted. The array is sorted if the number of inversions are 0.
Submit Your Solution
Tags: No Tags on this question yet!
54 / 137
#include <iostream>
using namespace std;
int main()
{
int arr[] = {1,2,3,4,5,6};
int n = sizeof(arr)/sizeof(arr[0]);
int d=4;
int temp[10];
for(int i=0;i<d;i++)
temp[i]=arr[i];
int j=0;
for(int i=d;i<n;i++,j++)
arr[j]=arr[i];
int k=0;
for(int i=n-d;i<n;i++,k++)
arr[i]=temp[k];
for(int i=0;i<n;i++)
cout<<arr[i]<<" ";
return 0;
}
AO(n*d)
BO(1)
CO(n)
DO(d)
Answer: Option D
Explanation:The given code rotates an input array by d. It does so by using an auxiliary array temp[] which stores first d elements of the original array. So the auxiliary space complexity will be O(d).
Submit Your Solution
55 / 137
#include <bits/stdc++.h>
using namespace std;
void func(int arr[], int left, int right)
{
while (left < right)
{
int temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
left++;
right--;
}
}
void printArray(int arr[], int size)
{
for (int i = 0; i < size; i++)
cout << arr[i] << " ";
}
int main()
{
int arr[] = {1,4,3,5};
int n = sizeof(arr) / sizeof(arr[0]);
func(arr, 0, n-1);
printArray(arr, n);
return 0;
}
AO(n log n)
BO(n)
CO(log n)
DO(1)
Answer: Option B
Explanation:The given code reverses the input array and then prints the resulting array. So the time complexity of the given code will linearly vary with the number of elements in the array and thus the time complexity will be O(n).
Submit Your Solution
Tags: No Tags on this question yet!
56 / 137
#include <bits/stdc++.h>
using namespace std;
void func(int a[], int n, int k)
{
if (k <= n)
{
for (int i = 0; i < k/2; i++)
swap(a[i], a[k-i-1]);
}
}
int main()
{
int a[] = {1, 2, 3, 4, 5};
int n = sizeof(a) / sizeof(int), k = 3;
func(a, n, k);
for (int i = 0; i < n; ++i)
cout << a[i]<<" ";
return 0;
}
AO(n log n)
BO(k)
CO(n)
DO(k log k)
Answer: Option B
Explanation:The given code reverses only a specified segment of the input array. This segment is decided by the value of k so the time complexity of the code will be O(k).
Submit Your Solution
Tags: No Tags on this question yet!
57 / 137
#include <bits/stdc++.h>
using namespace std;
int min(int x, int y)
{ return (x < y)? x: y; }
int func(int arr[], int n)
{
int *jump = new int[n];
int i, j;
if (n == 0 || arr[0] == 0)
return INT_MAX;
jump[0] = 0;
for (i = 1; i < n; i++)
{
jump[i] = INT_MAX;
for (j = 0; j < i; j++)
{
if (i <= j + arr[j] && jumps[j] != INT_MAX)
{
jump[i] = min(jump[i], jump[j] + 1);
break;
}
}
}
return jump[n-1];
}
int main()
{
int arr[] = {1, 3, 6, 1, 9,7};
int size = sizeof(arr)/sizeof(int);
cout<< func(arr,size);
return 0;
}
AO(n2)
BO(n log n)
CO(n)
DO(n1/2)
Answer: Option A
Explanation:The given code finds the minimum number of steps required to reach the end of an array by using dynamic programming. As there is a nested loop in the code so the time complexity will be O(n2).
Submit Your Solution
Tags: No Tags on this question yet!
58 / 137
5/9 of the part of the population in a villagae are males.if 30 % of the males are married.the percentage of unmarried females in the total population is?
A13.45%
B43.20%
C45%
D27.78%
ENone of above
Answer: Option D
Explanation:Let total population = p
no. of males =5p/9
no. of females =(p-5p/9)=4p/9
married males = 30% of 5p/9=30*5p/100*9 =p/6
married females = p/6
unmarried females =(4p/9-p/6)=5p/18
%age of unmarried females in the total population = {(5p/18)/p}*100= 250/9% = 27.78%
Submit Your Solution
59 / 137
Anil bought a T.V with 20% discount on the labeled price . Had he bought it with 25% discount, he would have saved Rs. 500. At what price did he buy the T.V?
A10000
B8000
C12000
D11340
ENone of above
Answer: Option B
Explanation:Let the labelled price of TV be Rs. x, then difference between 80% of x and 75% of x is Rs. 500.
=> 0.8x - 0.75x = 500
=> 0.05x =500 or x=10000
So the buying price=80% of x= 0.8*10000=Rs. 8000
Submit Your Solution
60 / 137
Water is continuously poured from a reservoir to a locality at the steady rate of 10,000 liters per hour. When delivery exceeds demand, the excess water is stored in a tank. If the demand for 8 consecutive three-hour periods is 10000,10000,45000,25000,40000,15000,60000 and 35000 liters respectively, what will be the minimum capacity required of the water tank (in 1000 litres) to meet the demand?
A10
B30
C40
D50
Answer: Option C
Explanation:In the period of First 3 hrs, the demand of water = 10000.
but the water poured by 10000 per hour.
Thus the end of 3 hours it will poured 30000 ltr then the excess of water = 20000.
Similarly at the end of Second 3 hrs period the excess of water 20000+20000 = 40000.
Third, 3 hrs water poured = 30000
already we have 40000 of excess water and demand 45000.
Then the excess water at the end of 3rd 3 hrs= 40000+30000–45000= 25000
Fourth 3 hrs. water = 25000+30000–25000= 30000
Fifth = 30000+30000–40000= 20000
Sixth = 20000+30000–15000=35000
Seventh = 35000+30000–60000= 5000
Eighth = 5000+30000–35000= 0
By analyzing the above results, we have 40000 ltrs is the highest measure of excess water.
So the minimum capacity of water tank = 40000 litres = 40
i.e. = 40
Submit Your Solution
Here is the list of questions asked in Cocubes paper Practice questions with Answers Page 6. Practice Cocubes Written Test Papers with Solutions and take Q4Interview Cocubes Online Test Questions to crack Cocubes written round test. Overall the level of the Cocubes Online Assessment Test is moderate. Only those candidates who clear the written exam will qualify for the next round, so practic all the questions here and take all the free tests before going for final selection process of Cocubes