# Infosys SP Technical Interview Questions

## Infosys SP Technical Interview Questions and Answers 2022

Find the latest Infosys SP Technical Interview Questions for Freshers for the 2022-23 batch students.

Page Highlights:-

• Infosys SP Recruitment Pattern
• Infosys SP Technical Interview Questions ### Infosys SP Recruitment Pattern

#### Online Test

There are three coding questions asked in the online test. The test has a sectional and overall cut-off.

• Question 1:- Basic questions on algorithms and data structures.
• Question 2:- Greedy’s Algorithm
• Question 3:- Dynamic Programming

Programming languages allowed in this exam:- C, C++, Java, Python

## Infosys SP Technical Interview Questions for Freshers

Find the common Infosys SP Technical Interview Questions asked to freshers for the 2022-23 batch.

### Infosys SP Technical Interview Questions

##### Question 1: Write a code for Bubble Sort.
Run
```#include

// Function to print array
void display(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
printf("%d ", arr[i]);
printf("\n");
}

// Main function to run the program
int main()
{
int array[] = {5, 3, 1, 9, 8, 2, 4,7};
int size = sizeof(array)/sizeof(array);

printf("Before bubble sort: \n");
display(array, size);

int i, j, temp;
for (i = 0; i < size-1; i++){

// Since, after each iteration right-most i elements are sorted
for (j = 0; j < size-i-1; j++) if (array[j] > array[j+1])
{
temp = array[j]; // swap the element
array[j] = array[j+1];
array[j+1] = temp;
}
}
printf("After bubble sort: \n");
display(array, size);
return 0;
}```
Run
```// Time Complexity : O(N^2)
// Space Complexity : O(1)
class Main
{
static void bubbleSort(int a[])
{
int len = a.length; // calculating the length of array
for (int i = 0; i < len-1; i++)
for (int j = 0; j < len-i-1; j++) if (a[j] > a[j+1]) //comparing the pair of elements
{
// swapping a[j+1] and a[i]
int temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}

/* Prints the array */
static void printArray(int a[])
{
int len = a.length;
for (int i = 0; i < len; i++)
System.out.print(a[i] + " "); //printing the sorted array

System.out.println();
}

// Main method to test above
public static void main(String args[])
{
int arr[] = {64, 34, 25, 12, 22, 11, 90};

bubbleSort(arr);//calling the bubbleSort function

System.out.println("Sorted array");

printArray(arr); //calling the printArray function
}
}```

### Output

```Sorted array
11 12 22 25 34 64 90
```
##### Question 2: What are ACID properties?

ACID Properties stand for:-

• A- Atomicity. The transaction is all or nothing. If one part of the transaction fails, the entire transaction fails.
• C-Consistency. The data must follow all validation rules. The transaction will not leave the database without being completed.
• I-Isolation. It provides concurrency control by ensuring that the concurrent property of execution is not met.
• D-Durability. If a transaction is committed it will remain so regardless of the situation, power loss, crashes, etc.
##### Question 3: What do you understand by joins?

Joins are used in SQL to retrieve data from multiple tables.

Read More:- Joins in SQL

##### Question 4: What are pointers in C++?

A pointer stores the address of a variable.

##### Question 5: Write a code for the following:-

“A has a list of cities and the distance between each pair of cities. Write a program to find the shortest possible route A can take such that A can visit all the cities exactly once and then return to the origin city.”

This is the Traveling Salesman Problem.

##### Question 6: What are the advantages of the Iterative Waterfall Model over the Waterfall Model?

The iterative Waterfall model provides feedback from one phase to its previous phase. This is something not available in Waterfall Model.

##### Question 7: What is the Agile model?

Agile is a type of software development life cycle model. It is a combination of two iterative and incremental software development models. It divides the requirements into multiple parts known as iterations and develops each part separately. Each iteration is planned, designed, implemented, tested, and deployed to customers.

##### Question 8: What is View?

A view is a virtual table containing a subset of the database’s data.

##### Question 9: How does a local variable from a global variable?

Where a global variable can be accessed globally, a local variable is only accessible in the current scope.

##### Question 10: What is a virtual function and what is a pure virtual function?

A virtual function is overridden in a derived class and instructs the C++ compiler to execute late binding on that function.
A pure virtual function is declared in the Parent Class and does not have any implementation, it only has a declaration.

##### Question 11: What is a database schema?

A database schema is an organization of data as a blueprint of how the database is constructed.

##### Question 12: How to solve ClassCastException?

ClassCastxception is the child class of RuntimeException arises in typecasting. It is solved by ensuring that while typecasting the new type belongs to one of its parent classes.

##### Question 13: What are tokens in C++?

A token is the smallest element of a C++ program containing meaning for the compiler. Types of tokens include Keywords, Identifiers, etc.

##### Question 14: What is STL?

STL or Standard Template Library consists of classes, algorithms, and iterators. The components of STL are accessed in the form of templates.

##### Question 15: What is collection API?

Collection API provides a set of classes and interfaces making it easier to work with collections of objects such as lists, maps, etc.

##### Question 16: What is memory management in Python?

Python has a private heap memory where all the Python objects and data structures are stored. The management of this heap is memory management. It is internally managed by the Python memory manager.

##### Question 17: Write a code to reverse a linked list
```#include
using namespace std;
class node
{
public:
int data;
node* next;//defining linked list.

node(int d)//making constructor for nodes
{
data = d;
next = NULL;
}
};
void insertAtTail(node*&head,int data)//function to insert new element at tail of the list
{
head = new node(data);
return;
}
node *tail = head;
while(tail->next != NULL)
{
tail = tail->next;
}
tail->next = new node(data);
}
int buildList(node*&head)//function to build the list.
{
int n;
cout<<"Enter the size of list:";
cin>>n;
cout<<endl;
int a=n;
cout<<"Enter data of the nodes\n";
while(n--){
int data;
cin>>data;
insertAtTail(head,data);//New element will be inserted at end.
}
return a;
}
{
return;
}
}
struct node* reverse(node* head, int k)//function to reverse linked list in groups
{
return NULL;
}
struct node* next=NULL;
struct node* prev=NULL;
int count=0;
while(curr && count<k){ next=curr->next;
curr->next=prev;
prev=curr;
curr=next;
count++;
}

return prev;
}
int main() //main function
{
int k;
node* head = NULL;

int n = buildList(head);
cout<<"Linked list data: ";
cout<<"\nEnter the group size: ";
cin>>k;
cout<<"\nAfter reversing linked list in groups of given size\n";
cout<<"Linked list data: ";
}```
```Output:
Enter the size of list:6

Enter data of the nodes
15
23
85
46
96
25
Linked list data: 15 23 85 46 96 25
Enter the group size: 3

After reversing linked list in groups of given size
Linked list data: 85 23 15 25 96 46```
```#include
#include
struct Node         // Structure of node
{
int item;
struct Node* next;
};
struct Node *reverse (struct Node *head, int m) /* this function reverses the linked list in groups of size m and
returns the pointer to the new head node*/
{
struct Node* current = head;
struct Node* next = NULL;
struct Node* previous = NULL;

void print_List(struct Node *node) //print function of the list
{
while (node != NULL)
{
printf("%d ",node->item);
node = node->next;
}
}
void insert(struct Node** head_ref, int new_data) //insert the data
{
struct Node* new_node =
(struct Node*) malloc(sizeof(struct Node));
new_Node->item = new_Data;
}
int counter = 0;
while (current != NULL && counter < m) //reverse first m nodes of the linked list
{
next = current->next;
current->next = previous;
previous = current;
current = next;
counter++;
}

if (next != NULL)
return previous;
}

int main()
{
struct Node* head = NULL;
printf("The linked list is: \n");
printf("\nReverse a Linked List in groups of given size like m = 4 here: \n");
return(0);
}```
```Output:-
The linked list is:
20  15  64  8  1  53  45  17  58  91
Reverse a Linked List in groups of given size like m = 4 here:
8   64  15  20  17  45  53  1  91  58

```
##### Question 18: What is the difference between calloc() and malloc()?

Both malloc() and calloc() are used to allocate dynamic memory. The difference between them is where malloc() takes a size and returns a pointer to a chunk of memory at least that big, and calloc() takes a number of elements and the size of each and returns a pointer to a chunk of memory at least big enough to hold them all.

##### Question 19: Write a code to merge two sorted arrays without using extra space.
```// C program to merge two sorted
// arrays with O(1) extra space.
#include

void merge(int arr1[], int arr2[], int m, int n)
{
// Iterate through all elements
// of ar2[] starting from the last element
for (int i = n - 1; i >= 0; i--)
{
/* Find the smallest element greater than ar2[i].
Move all elements one position ahead till the
smallest greater element is not found */
int j, last = arr1[m - 1];

for (j = m - 2; j >= 0 && arr1[j] > arr2[i]; j--)
arr1[j + 1] = arr1[j];

// If there was a greater element
if (j != m - 2 || last > arr2[i])
{
arr1[j + 1] = arr2[i];
arr2[i] = last;
}
}
}

// Driver program
int main()
{

int m, n;

scanf("%d", &m);

int arr1[m];

for(int i=0; i<m; i++) scanf("%d", &arr1[i]);

scanf("%d", &n);

int arr2[n];

for(int i=0; i<n; i++) scanf("%d", &arr2[i]);

merge(arr1, arr2, m, n);

printf("After Merging nFirst Array: ");

for (int i = 0; i < m; i++)
printf("%d ", arr1[i] );

printf( "\nSecond Array: ");

for (int i = 0; i < n; i++)
printf("%d ", arr1[i] );

return 0;
}```
Run
```#include
using namespace std;

void mergeSort(int[],int,int);
void merge(int[],int,int,int);

void printArray(int arr[], int size){
int i;
for(i = 0; i < size; i++){
cout << arr[i] << " ";
}
cout << endl;
}

int main()
{
int array[]= {8, 4, 5, 1, 3, 9, 0, 2, 7, 6};
int i;

int size = sizeof(array)/sizeof(array);
printArray(array, size);

mergeSort(array, 0, size-1);
printArray(array, size);
}

void mergeSort(int a[], int left, int right)
{
int mid;
if(left < right)
{
// can also use mid = left + (right - left) / 2
// this can avoid data type overflow
mid = (left + right)/2;

// recursive calls to sort first half and second half subarrays
mergeSort(a, left, mid);
mergeSort(a, mid + 1, right);
merge(a, left, mid, right);
}
}

void merge(int arr[], int left, int mid, int right)
{
int i, j, k;
int n1 = mid - left + 1;
int n2 = right - mid;

// create temp arrays to store left and right subarrays
int L[n1], R[n2];

// Copying data to temp arrays L[] and R[]
for (i = 0; i < n1; i++)
L[i] = arr[left + i];
for (j = 0; j < n2; j++)
R[j] = arr[mid + 1 + j];

// here we merge the temp arrays back into arr[l..r]
i = 0; // Starting index of L[i]
j = 0; // Starting index of R[i]
k = left; // Starting index of merged subarray

while (i < n1 && j < n2)
{
// place the smaller item at arr[k] pos
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
}
else {
arr[k] = R[j];
j++;
}
k++;
}
// Copy the remaining elements of L[], if any
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
// Copy the remaining elements of R[], if any
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}```

### Output

```8 4 5 1 3 9 0 2 7 6
0 1 2 3 4 5 6 7 8 9```
##### Question 20: What is the lambda function in python?

Lambda function also known as the anonymous function is used to reduce length of code.

For more Technical Interview Questions, check out: Technical Interview Questions Dashboard

## Top 100 Puzzles ## Interview Prep. 