skip to content

Join us to discover alumni reviews, ratings, and feedback, or feel free to ask any questions you may have!

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Counselling from

Experts

Industry Professional today!

By continuing you agree to our Terms of Service and Privacy Policy, and you consent to receive offers and opportunities from the Analytics Jobs platform listed EdTech’s by telephone, text message, and email.

Infosys is known to ask a range of coding questions during interviews. These can include such topics as data structures, algorithms, object-oriented design principles, system design concepts, and software engineering fundamentals. Examples of coding questions may involve sorting arrays or linked lists, finding the maximum or minimum value in an array, implementing a binary search tree or other data structure from scratch, writing code for a specific algorithm (e.g., linear search or quicksort), solving puzzles involving recursion and indexing/pointers. Additionally, Infosys interviews typically involve written tests assessing problem-solving skills by asking candidates to write programs or solve programming puzzles.

Some of the sample coding questions and aswers are below:

1.

Write a program to reverse the digits of a given number.Answer:

// C++ Program to Reverse a Number

#include

using namespace std;

int main()

{

int n, reverse = 0;

cout << “Enter a number: “;

cin >> n;

while(n != 0)

{

reverse = (reverse*10)+(n%10);

n /= 10;

}

cout << “Reversed Number: ” << reverse;

return 0;

}

2. Write a program to find the maximum and minimum element in an array.Answer:

// C++ program to find maximum and minimum element in an array

#include using namespace std;

int main()

{ int arr[] = {1, 2, 4, 5, 6};

int size = sizeof(arr)/sizeof(arr[0]);

// Initialize maximum element int max = arr[0];

// Traverse array elements from second and // compare every element with current max

for (int i = 1; i < size; i++)

{

if (arr[i] > max) max = arr[i];

}

cout << “Maximum element is: ” << max << endl;

// Initialize minimum element int min = arr[0];

// Traverse array elements from second and // compare every element with current min

for (int i = 1; i < size; i++)

{

if (arr[i] < min)

min = arr[i];

}

cout << “Minimum element is: ” << min; return 0;

}

3. Write a program to find the sum of all elements in an array.Answer: // C++ program to find sum of all elements in an array

#include using namespace std;

int main()

{

int arr[] = {1, 2, 3, 4, 5};

int size = sizeof(arr)/sizeof(arr[0]);

int sum = 0;

// Iterating through array elements and adding them

for (int i = 0; i < size; i++)

sum += arr[i];

cout << “Sum of all array elements is: ” << sum;

return 0;

}

4. Write a program to check if a given number is prime or not.Answer: // C++ program to check if a given number is prime or not

#include using namespace std;

int main()

{

int n;

cout << “Enter a positive integer: “;

cin >> n; bool isPrime = true;

// Iterating from 2 to half of the given number

for (int i = 2; i <= n/2; i++)

{

// Condition for non prime number

if (n % i == 0)

{

isPrime = false;

break;

}

}

// Print result if (isPrime)

cout << n << ” is a prime number”;

else cout << n << ” is not a prime number”;

return 0;

}

5. Write a program to find the largest palindrome in a given string.Answer: // C++ program to find the largest palindrome in a given string #include using namespace std;

int isPalindrome(string str)

{

// Initialize left and right pointers int l = 0;

int h = str.length() – 1;

// Keep comparing characters while they are same while (h > l)

{

if (str[l++] != str[h–])

return 0;

}

// If the complete string is palindrome, then return true

return 1;

}

// Function to find the longest palindromic substring

int LongestPalinSubstr(string str)

{ int n = str.length();

// The complete string may be considered as palindrome

int maxLength = 1;

int start = 0;

// Consider every possible substring

for (int i = 1; i < n; ++i)

{

// Find the longest even length palindrome with center points

// as i-1 and i.

int low = i – 1;

int high = i;

while (low >= 0 && high < n && str[low] == str[high])

{ if (high – low + 1 > maxLength)

{ start = low;

maxLength = high – low + 1;

}

// Expand in both directions low–;

high++;

}

// Find the longest odd length palindrome with center point as i

low = i – 1;

high = i + 1;

while (low >= 0 && high < n && str[low] == str[high])

{ if (high – low + 1 > maxLength)

{ start = low;

maxLength = high – low + 1;

}

// Expand in both directions

low–;

high++;

}

}

// Return the longest palindromic substring

//return maxLength;

return str.substr(start, maxLength);

}

// Driver code

int main()

{

string str = “forgeeksskeegfor”;

cout << LongestPalinSubstr(str);

return 0;

}

Have a look at the following Python questions and answer. I hope that will help:

1. Write a program to find the longest common substring between two strings.Answer:

def longest_common_substring(str1, str2):

# convert strings to lists

s1 = list(str1)

s2 = list(str2)

# initialize the matrix

matrix = [[0 for x in range(len(s2))] for y in range(len(s1))]

# loop through the strings and populate the matrix

for i in range(len(s1)):

for j in range(len(s2)):

if s1[i] == s2[j]:

# check the surrounding cells

if i == 0 or j == 0:

matrix[i][j] = 1

else:

matrix[i][j] = matrix[i-1][j-1]+1

# find the longest substring length

max_length = 0

# loop through the matrix to get maximum length

for i in range(len(s1)):

for j in range(len(s2)):

if matrix[i][j] > max_length:

max_length = matrix[i][j]

# loop through the matrix and get the longest common substring

result = “”

for i in range(len(s1)):

for j in range(len(s2)):

if matrix[i][j] == max_length:

# get the substring from string1 and string2

result = str1[i-max_length+1:i+1]

# return the longest common substring

return result

2. Write a program to find the second largest element in an array.Answer:

def second_largest(array):

# set the initial maximum and second maximum

max1 = 0

max2 = 0

# loop through the array and find the second largest element

for i in range(len(array)):

if array[i] > max1:

max2 = max1

max1 = array[i]

elif array[i] > max2 and array[i] != max1:

max2 = array[i]

# return the second largest element

return max2

3. Write a program to print all the permutations of a string.Answer:

def permutations(string):

# base condition

if len(string) == 0:

return []

# recursive case

prev_list = permutations(string[1:len(string)])

next_list = []

# loop through the previous list and create new list with added character

for i in range(len(prev_list)):

for j in range(len(string)):

new_str = prev_list[i][0:j]+string[0]+prev_list[i][j:len(string)-1]

if new_str not in next_list:

next_list.append(new_str)

# append the single character to the list

next_list.append(string[0])

# return the list

return next_list

4. Write a program to check if a given string is a palindrome or not.Answer:

def is_palindrome(string):

# set the initial pointers

start = 0

end = len(string)-1

# loop through the string and compare the characters

while start < end:

if string[start] != string[end]:

return False

start += 1

end -= 1

# return true if the string is a palindrome

return True

5. Write a program to find the number of occurrences of a character in a string.Answer:

def count_char(string, char):

# set the initial count

count = 0

# loop through the string and increment the counter if a character is found for i in range(len(string)):

if string[i] == char:

count += 1

# return the count

return count

If you require more coding questions, reply here.