## Intel Interview Question for Software Engineer / Developers

Team: Firmware
Country: United States
Interview Type: In-Person

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

reverserArray(int a[],int initial,int last){

if(initial < last)
reverserArray(a,initial+1,last-1);
swap(a,inital,last);

}

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

Silly question.

``````void reverse(int *a, int n) {
if (n <= 0) return;
swap(a[0], a[n-1]);
reverse(++a, n-1);
}``````

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

This wont work. Probably typo. pass n-2 instead of n-1 for the recursive call?

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

Yea, we have to pass n-2 because ++a moves it by one more

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

Corrected code:-

``````void reverse(int *a, int n) {
if (n <= 0) return;
swap(a[0], a[n-1]);
reverse(++a, n-2);``````

}

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

There is no silly question. Only arrogant people.

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

There are no arrogant people. Only sensitive idiots.

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

fuck you all
bazinga !!!

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

I guess the check needs to be modified like this

void reverse(int *a, int n) {
if (n <= 1) return;
swap(a[0], a[n-1]);
reverse(++a, n-1);
}

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

Considering swap function, don't we need to call swap(&a[0], &a[n-1])?

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

No, arrays are already in memory, so you're directly accessing it.

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

This solution is wrong.. lets see how..
take the string as "abcd"
in first call you make it "dbca"
then "dcba".. its reversed.. but wait.. n is still far from 0...
you reverse again it to.. "dbca".
then "abcd"..

So my friend.. make the recursion calls till n reaches ceil(n/2) (ceil as you are coming from n to middle; in case of odd characters the middle char remains at its original place.)

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

``````/*  Move first element to last position, and shift other elements to left */
void Bubble(T *a, int len){
if (len <= 1) return;
T tmp = a[0];
a[0] = a[1];
a[1] = tmp;
Bubble(++a, --len);
}
void Reverse(T * a, int len) {
Bubble(a, len); /* first move first element to last */
Reverse(a, --len); /* now reverse the initial portition of bubbled array*/
}``````

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

Of course, the Reverse needs to to return when length is 1.

So corrected code:

``````/*  Move first element to last position, and shift other elements to left */
void Bubble(T *a, int len){
if (len <= 1) return;
T tmp = a[0];
a[0] = a[1];
a[1] = tmp;
Bubble(++a, --len);
}
void Reverse(T * a, int len) {
if (len <= 1) return;
Bubble(a, len); /* first move first element to last */
Reverse(a, --len); /* now reverse the initial portition of bubbled array*/
}``````

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

``````#include <iostream>

using namespace std;

void reverse_array(int array[], int index, int len) {
if (index >= len - 1) return;
array[index] = array[index]^array[len - 1];
array[len - 1] = array[index]^array[len - 1];
array[index] = array[index]^array[len - 1];
reverse_array(array, index + 1, len - 1);
}

int main() {
int array[10];
for (int i = 0; i < 10; ++i)
array[i] = i;
reverse_array(array, 0, 10);
for (int i = 0; i < 10; ++i)
cout << array[i] << endl;
}``````

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

``````#include "stdio.h"
#define MAX 10

void printarr(int a[],int n)
{
printf("\nArray elements : ");
int i;
for(i=0;i<n;i++)
printf(" %d",a[i]);
}

void reverse(int a[],int start,int end)
{
int temp;
temp=a[start];
a[start]=a[end];
a[end]=temp;

if(start==end ||start==end-1)
return;
reverse(a,start+1,end-1);
}

int main()
{
int arr[MAX];
int n,i;
printf("Enter size of array : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter element : ");
scanf("%d",&arr[i]);
}
printarr(arr,n);
reverse(arr,0,n-1);
printarr(arr,n);
}``````

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

You case is not correct. consider array only has two elements. It's not get reversed.

Solution: change if(start==end ||start==end-1)
to if(start<=end)

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

#include <iostream>
using namespace std;

void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}

int main()
{
int a[]={1,2,3,4,5,6,7,8,9};
int len=sizeof(a)/sizeof(int); //9
for(int i=0;i<len/2;i++) //4
swap(a[i],a[len-1-i]);
for(int j=0;j<len;j++)
cout << a[j]<<"\t";
return 0;
}

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

#include <iostream>
using namespace std;

void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}

int main()
{
int a[]={1,2,3,4,5,6,7,8,9};
int len=sizeof(a)/sizeof(int); //9
for(int i=0;i<len/2;i++) //4
swap(a[i],a[len-1-i]);
for(int j=0;j<len;j++)
cout << a[j]<<"\t";
return 0;
}

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

char *arrayrec(char arr[],int N,int i=0)
{
if(i>=N/2)
return arr;
char temp=arr[i];
arr[i]=arr[N-i-1];
arr[N-i-1]=temp;
arrayrec(arr,N,++i);

}

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

#include<stdio.h>
void rev_arr(int [],int,int);

int main()
{
int i=0;
int arr[10]={1,2,3,4,5,6,7,8,9,0};
rev_arr(arr,0,9);
for(i=0;i<10;i++)
printf("%d\n",arr[i]);
return 0;
}

void rev_arr(int arr[],int min,int max)
{
if(min>4)
return;
int temp=arr[min];
arr[min]=arr[max];
arr[max]=temp;
rev_arr(arr,min+1,max-1);
}

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

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void rev(int *,int *);
void main(){
int arr[]={1,2,3,4,5,6,7,8,9,0};
int i;
printf("\nThe array is:");
for(i=0;i<10;i++)
printf("%d\t",arr[i]);
rev(&arr[0],&arr[9]);
printf("\nThe New array is:");
for(i=0;i<10;i++) {
printf("%d\t",arr[i]);
sleep(1);
}
getch();
}
void rev(int *p, int *q){

int temp;
temp=*p;
*p=*q;
*q=temp;
if(q>p){
rev(p+1,q-1);
}
}

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

#include<iostream>
using namespace std;

void printArray(int n[],int i)
{
cout<<n[i]<<endl;
if(i>0)
{
printArray(n,i-1);
}
}
int main()
{
int n[]={1,2,3,4,5,6,7,8};
printArray(n,7);
return 0;
}

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

``````#include<iostream>
using namespace std;

void printArray(int n[],int i)
{
cout<<n[i]<<endl;
if(i>0)
{
printArray(n,i-1);
}
}
int main()
{
int n[]={1,2,3,4,5,6,7,8};
printArray(n,7);
return 0;
}``````

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

``````#include<iostream>
using namespace std;

void printArray(int n[],int i)
{
cout<<n[i]<<endl;
if(i>0)
{
printArray(n,i-1);
}
}
int main()
{
int n[]={1,2,3,4,5,6,7,8};
printArray(n,7);
return 0;
}``````

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

//============================================================================
// Name : reversearray.cpp
// Version :
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
cout << "\nProgram to reverse array";
cout << "\nEnter iterations";
int T;
cin >> T;
cout << "\nEnter array size";
int size;
cin >> size;
int arr[size], i, temp, iter;
cout << "\nReversing array";
for(iter=0; iter<T; iter++){
cout << "\nEnter array elements:";
for(i=0; i< size; i++)
cin >> arr[i];
for(i=0; i< size/2; i++){
temp=arr[i];
arr[i]=arr[size-i-1];
arr[size-i-1]=temp;
}
cout << "\nReversed array";
for(i=0; i< size; i++) {
cout << arr[i] << endl;
}
}

return 0;
}

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

//============================================================================
// Name : reversearray.cpp
// Version :
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
cout << "\nProgram to reverse array";
cout << "\nEnter iterations";
int T;
cin >> T;
cout << "\nEnter array size";
int size;
cin >> size;
int arr[size], i, temp, iter;
cout << "\nReversing array";
for(iter=0; iter<T; iter++){
cout << "\nEnter array elements:";
for(i=0; i< size; i++)
cin >> arr[i];
for(i=0; i< size/2; i++){
temp=arr[i];
arr[i]=arr[size-i-1];
arr[size-i-1]=temp;
}
cout << "\nReversed array";
for(i=0; i< size; i++) {
cout << arr[i] << endl;
}
}

return 0;
}

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.