## Interview Question for Data Engineers

Country: United States

Comment hidden because of low score. Click to expand.
0
of 0 vote

int a[]={1,2,5,6,10,11,12,18,21,22,23,100};
int i=0;
int j=1;
while(j<=a[a.length-1]){
if(a[i]==j){
j++;
}else{
while(j<=a[i]){
if(a[i]==j){
j++;
break;
}
System.out.println(j);
j++;
}
}
i++;
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

int a[]={1,2,5,6,10,11,12,18,21,22,23,100};
int i=0;
int j=1;
while(j<=a[a.length-1]){
if(a[i]==j){
j++;
}else{
while(j<=a[i]){
if(a[i]==j){
j++;
break;
}
System.out.println(j);
j++;
}
}
i++;
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

{int a[]={1,2,5,6,10,11,12,18,21,22,23,100};
int i=0;
int j=1;
while(j<=a[a.length-1]){
if(a[i]==j){
j++;
}else{
while(j<=a[i]){
if(a[i]==j){
j++;
break;
}
System.out.println(j);
j++;
}
}
i++;
}}

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````void FindGap(const std::vector<int>& data)
{
assert(!data.empty());
auto min = data.front();
auto max = data.back();
auto curIt = data.cbegin();
bool first = true;

for(auto i = min; i < max; i++)
if(i != *curIt)
{
if(!first)
std::cout << ',';
std::cout << i;
first = false;
}
else
curIt++;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public static void main (String[] args) {
int[] arr={1,2,5,7,11};
int len=arr.length;
int j=0;
for(int i=1;i<=arr[len-1];i++)
{
if(arr[j]==i)
j++;

else
{
System.out.println(i);
}
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

A correct solution for this during interview would depend on some clarifications:

* Is the input already sorted?
* If input is not sorted, do we want to optimize for time or space?
* what is exactly considered a gap? the sequence should start with 1 or with the minimum value already present?

Comment hidden because of low score. Click to expand.
0
of 0 vote

What? Is that seriously MS Question ? No Way!!! ROFL

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````#include <stdio.h>
#define SIZE 5
int main (void) {
int a[SIZE] = {1,2,5,6,9};
int i,p;
for(i = a[0], p=0; i < a[SIZE-1]; i++) {
if (a[p] == i) {p++; continue;}
printf("%d ", i);
}
return 0;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

Does the comment work?

Comment hidden because of low score. Click to expand.
0
of 0 vote

public class FindGap {

public static void main(String[] args) {
int a [] = {1, 2, 5, 6, 10};
printGap(a);

}

public static void printGap(int a[]) {
int max = maxElementOfArray(a);
int j = 0;
for (int i = 0; i < max; i++) {
if (a[j]==i) {
j++;
} else if(i > 0) {
System.out.print(i +", ");
}
}
}

public static int maxElementOfArray(int a[]) {
int max = Integer.MIN_VALUE;
for (int i : a) {
if (i > max) {
max = i;
}
}
return max;
}
}

Comment hidden because of low score. Click to expand.
-1
of 1 vote

``````private static void GetGap()
{
int[] vals = { 1, 2, 5, 6, 10 };
var max = vals.Max();
List<int> gaps = new List<int>();
for (int i = 0; i < max; i++)
{
if (!vals.Contains(i) && i >  0 )

}

Console.WriteLine( string.Join("," ,gaps.Select(x=>x)));

}``````

Comment hidden because of low score. Click to expand.
-1
of 1 vote

``````private static void GetGap()
{
int[] vals = { 1, 2, 5, 6, 10 };
var max = vals.Max();
List<int> gaps = new List<int>();
for (int i = 0; i < max; i++)
{
if (!vals.Contains(i) && i >  0 )

}

Console.WriteLine( string.Join("," ,gaps.Select(x=>x)));

}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.