Get Off-Campus Placement Jobs Info !!!
Programs asked in Mettl Coding Round
Click To Practce List of Programs asked in Nagarro !!!

# Practice Questions & Answers :: Cocubes

34.5K

## Total Practice Qs: 57+

NA
SHSTTON
45
Solv. Corr.
83
Solv. In. Corr.
128
Attempted
0 M:0 S
Avg. Time

51 / 57

Choose the correct option.

Which of the following is not an application of sorted array?

AHash Tables

BCommercial computing

CPriority Scheduling

DDiscrete Mathematics

| | Topic: | Asked In Cocubes |

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.

Tags: No Tags on this question yet!

NA
SHSTTON
4
Solv. Corr.
4
Solv. In. Corr.
8
Attempted
0 M:0 S
Avg. Time

52 / 57

Choose the correct option.

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)

| | Topic: | Asked In Cocubes |

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.

Tags: No Tags on this question yet!

NA
SHSTTON
1
Solv. Corr.
4
Solv. In. Corr.
5
Attempted
0 M:0 S
Avg. Time

53 / 57

Choose the correct option.

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

| | Topic: | Asked In Cocubes |

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.

Tags: No Tags on this question yet!

NA
SHSTTON
7
Solv. Corr.
52
Solv. In. Corr.
59
Attempted
0 M:0 S
Avg. Time

54 / 57

What will be the auxiliary space complexity of the following code?
#include <iostream>
using namespace std;
int main()
{
int arr[] = {1,2,3,4,5,6};
int n = sizeof(arr)/sizeof(arr);
int d=4;
int temp;

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)

| | Topic: | Asked In CapgeminiCocubes |

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).

Tags: Capgemini

NA
SHSTTON
12
Solv. Corr.
15
Solv. In. Corr.
27
Attempted
0 M:0 S
Avg. Time

55 / 57

What will be the time complexity of the following code?
#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);
func(arr, 0, n-1);
printArray(arr, n);
return 0;
}

AO(n log n)

BO(n)

CO(log n)

DO(1)

| | Topic: | Asked In Cocubes |

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).

Tags: No Tags on this question yet!

NA
SHSTTON
1
Solv. Corr.
2
Solv. In. Corr.
3
Attempted
0 M:0 S
Avg. Time

56 / 57

What will be the time complexity of the following code?
#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)

| | Topic: | Asked In Cocubes |

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).

Tags: No Tags on this question yet!

NA
SHSTTON
5
Solv. Corr.
21
Solv. In. Corr.
26
Attempted
0 M:0 S
Avg. Time

57 / 57

What will be the time complexity of the following code?
#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)
return INT_MAX;

jump = 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)

| | Topic: | Asked In Cocubes |

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). 