Interview Question


Country: United States




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

#include<stdio.h>
#include<conio.h>
void main()
{int t=0,arr[75],temp,count=-1,i=0,j;
clrscr();
printf("enter numbers and -999 to exit");
while(arr[i-1]!=-999){
scanf("%d",&arr[i]);
i++;
count++;}
printf("\nelements are");
for(i=0;i<count;i++){
printf("\t %d",arr[i]);}
for(i=0;i<count;i++){
for(j=i+1;j<count-1;j++){
if(arr[i]>arr[j]){
temp = arr[i];
arr[i]=arr[j];
arr[j]=temp;}}}
for(i=0;i<count;i++){
for(j=i+1;j<count-1;j++){
if(arr[i]==arr[j]){
t=1;}}
if(t==1){
arr[i]=0;
t=0;}}
printf("\nelements are");
for(i=0;i<count;i++){
printf("\t %d",arr[i]);}
getch();}

- Srinivas Reddy A June 14, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Test
    fun test() {
        val data = arrayOf(4, 6, 3, 33, 3, 1, 3,3,24,4,5,62,1)
        cancelDoubles(data)
        sort(data)
        data.forEach { print("$it ") }
    }

    private fun cancelDoubles(data: Array<Int>){
        for (i in data.indices) {
            for (j in i+1 until data.size) {
                if(data[j] != 0 && data[j] == data[i]){
                    data[j] = 0
                }
            }
        }
    }

    private fun sort(data: Array<Int>) {
        for (i in data.indices) {
            for (j in i+1 until data.size) {
                if (data[i] > data[j]) {
                    val tmp = data[i]
                    data[i] = data[j]
                    data[j] = tmp
                }
            }
        }
    }

- Giordano B. June 15, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ArrayDuplicate {

public static void main(String[] args) {

int[] a = new int[] { 6,1,1,22,9, 7,7 };

for (int i=0;i<a.length;i++) {
for (int j=i+1;j<a.length;j++) {

if (a[i] > a[j]) {
int temp = a[i];
a[i]=a[j];
a[j]=temp;
}
if(a[i]==a[j]) {
a[j]=a[i];
a[i]=0;
}
}
}

for (int k=0;k<a.length;k++) {
System.out.println(a[k]);
}

}

}

- mrmjap June 15, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String [] args) {

        int[] a = new int[] { 6,1,1,22,9, 7,7 };
        int[] output = new int[a.length];
            for(int i= 0; i < a.length; i ++) {
                for(int j = i+1; j < a.length; j++) {
                    if(a[i] > a[j]) {
                        int tmp = a[i];
                        a[i] = a[j];
                        a[j] = tmp;
                    }
                   if(a[i] == a[j] && a[i] != 0) {
                        a[j] = a[i];
                        a[i] = 0;
                        i = 0;
                        break;
                    }
                }
            }
        for(int x=0; x < a.length; x++) {
            System.out.println(a[x]);
        }

    }

- Anonymous June 17, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String [] args) {

        int[] a = new int[] { 6,1,1,22,9, 7,7 };
        int[] output = new int[a.length];
            for(int i= 0; i < a.length; i ++) {
                for(int j = i+1; j < a.length; j++) {
                    if(a[i] > a[j]) {
                        int tmp = a[i];
                        a[i] = a[j];
                        a[j] = tmp;
                    }
                   if(a[i] == a[j] && a[i] != 0) {
                        a[j] = a[i];
                        a[i] = 0;
                        i = 0;
                        break;
                    }
                }
            }
        for(int x=0; x < a.length; x++) {
            System.out.println(a[x]);
        }

    }

- Virender Asija June 17, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String [] args) {

        int[] a = new int[] { 6,1,1,22,9, 7,7,23,1,9 };
        int zeroSize = 0;
            for(int i= zeroSize; i < a.length; i ++) {
                for(int j = i+1; j < a.length; j++) {
                    if(a[i] > a[j]) {
                        int tmp = a[i];
                        a[i] = a[j];
                        a[j] = tmp;
                    }
                   if(a[i] == a[j] && a[i] != 0) {
                        a[j] = a[i];
                        a[i] = 0;
                        i = 0;
                        zeroSize++;
                        break;
                    }
                }
            }
        for(int x=0; x < a.length; x++) {
            System.out.println(a[x]);
        }

    }

- Virender Asija June 17, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for (var i = 1; i < arr.Length; i++ )
{
    var index = i;
	var pivot = arr[index];
	while ((index > 0) && (arr[index - 1] >= pivot))
	{
	   if (arr[index - 1] == pivot)
	   {
	      pivot = 0;
	   }
	
	   arr[index--] = arr[index];
	}
	arr[index] = pivot;
}

for (var i = 0; i < arr.Length; i++)
{
         Console.WriteLine(arr[i]);
}

- Ratish Philip June 19, 2018 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More