Table of Contents

Infosys Coding Questions & Answers (2024)

Infosys coding questions
Table of Contents

In today’s competitive job market, coding skills are crucial for success, especially when applying for a role at one of the top technology companies like Infosys. With a strong emphasis on programming, problem-solving, and technical proficiency, Infosys aims to hire individuals who can efficiently write, debug, and optimise code. Whether you’re a recent graduate or an experienced professional looking to join Infosys, you must be prepared to showcase your coding abilities through their recruitment process.

This article is designed to provide you with a comprehensive guide to coding skills essential for Infosys recruitment, detailed insights into their coding assessment format, and 20 carefully selected coding questions with answers. These questions cover various topics such as arrays, strings, linked lists, stacks, queues, trees, graphs, dynamic programming, recursion, and more. Additionally, we will discuss practical tips and tricks to help you excel in the Infosys coding assessments.

If you’re serious about landing a job at Infosys, mastering these coding concepts and practising them regularly is crucial. Let’s dive into the essential coding skills and strategies needed to ace the Infosys recruitment process.

Coding Skills Essential for Infosys

Coding skills are the foundation of any technical interview, and Infosys places a high value on them. To succeed in their coding assessments and technical interviews, you need to focus on several core areas. Below, we’ll explore the essential coding skills that Infosys expects candidates to master.

Core Programming Languages

When preparing for Infosys coding assessments, it’s important to be proficient in one or more of the following programming languages:

  • Java: Known for its platform independence, Java is a popular language for many Infosys projects. Its object-oriented nature allows for clean, modular code that is easy to maintain. You’ll often encounter coding problems that require you to use Java’s built-in libraries and features.
  • Python: Python has gained popularity due to its simplicity and wide range of libraries. Infosys also includes Python in its coding assessments because of its ease of use for both beginners and experienced developers. It is commonly used for solving algorithmic problems efficiently.
  • C++: C++ provides more control over memory and system resources than many other programming languages. It is also known for its efficiency in handling large-scale data structures and algorithms. Many Infosys coding assessments may require candidates to solve problems in C++ due to its flexibility.

Data Structures and Algorithms

Data structures and algorithms are the building blocks of efficient programming. Infosys emphasises these concepts during its recruitment process because they allow you to solve complex problems efficiently. Here are the key areas you should focus on:

Arrays: Arrays are one of the most fundamental data structures. You should be comfortable with common operations such as traversal, insertion, deletion, searching, and sorting. Problems involving array manipulation, such as reversing an array or rotating it, are frequently asked in coding assessments.

Strings: Strings are another critical data structure, and problems involving string manipulation are common in coding assessments. You should be able to perform operations such as reversing a string, finding substrings, checking for palindromes, and determining if two strings are anagrams.

Linked Lists: Linked lists are a dynamic data structure used in various real-world applications. You should be familiar with both singly and doubly linked lists and understand how to perform operations such as insertion, deletion, traversal, and reversal.

Trees: Binary trees and binary search trees (BSTs) are important data structures in coding assessments. You should be able to implement and traverse trees (inorder, preorder, postorder) and perform operations such as insertion, deletion, and searching in a BST.

Graphs: Graphs are widely used in complex problems involving networks and connections. You should understand graph representations (adjacency matrix, adjacency list) and traversal algorithms such as Breadth-First Search (BFS) and Depth-First Search (DFS). Additionally, be familiar with shortest path algorithms like Dijkstra’s and Bellman-Ford.

Dynamic Programming (DP): DP is an optimization technique used to solve problems by breaking them down into smaller subproblems. Common DP problems include the Fibonacci series, knapsack problem, and various combinatorial problems.

Recursion: Recursion is a method where a function calls itself to solve smaller instances of a problem. You should be familiar with recursive solutions to problems such as calculating factorials, finding Fibonacci numbers, solving the Tower of Hanoi, and implementing backtracking algorithms.

Problem-Solving and Logical Reasoning

Infosys evaluates candidates on their ability to think critically and solve problems effectively. You need to demonstrate strong problem-solving skills by identifying the optimal approach to solve a problem. Logical reasoning also plays a vital role in coding assessments, as many problems require you to apply deductive reasoning to reach the correct solution.

Practising coding challenges that involve both problem-solving and logical reasoning will improve your ability to tackle complex questions in Infosys assessments.

Object-Oriented Programming (OOP) Concepts

Infosys places a strong emphasis on object-oriented programming (OOP) principles. Understanding OOP concepts allows you to write clean, modular, and reusable code. Key OOP concepts you should be familiar with include:

Classes and Objects: A class is a blueprint for creating objects, and an object is an instance of a class. You should understand how to define and use classes and objects in your code.

Inheritance: Inheritance allows a class to inherit properties and methods from another class. This is useful for code reuse and simplifying code structure.

Polymorphism: Polymorphism allows objects of different classes to be treated as objects of a common base class. You should understand how to implement polymorphism in your code to handle different data types in a generic way.

Encapsulation: Encapsulation involves bundling data and methods that operate on that data within a class. This helps protect the data from outside interference and misuse.

Abstraction: Abstraction involves hiding the internal implementation details of a class and exposing only the necessary parts to the user. This makes code more user-friendly and easier to maintain.

Mastering these OOP principles will enable you to write well-structured code that is easy to understand and maintain, which is crucial for both coding assessments and technical interviews at Infosys.

Infosys Coding Assessment Format

Understanding the format of Infosys coding assessments is essential for your preparation. The company uses a structured approach to evaluate candidates’ coding skills, problem-solving abilities, and technical knowledge. Below, we’ll explore the different types of coding assessments you may encounter during Infosys recruitment.

Types of Coding Assessments

Online Coding Tests: These tests are conducted online and are typically hosted on coding platforms such as HackerRank or Codility. You will be required to solve multiple coding problems within a specified time frame. The problems will test your knowledge of algorithms, data structures, and coding efficiency.

Technical Interviews: After successfully clearing the online coding test, you will be invited to attend a technical interview. During the interview, you may be asked to solve coding problems on paper or a whiteboard. The interviewer will assess your coding skills, problem-solving approach, and how you think through and explain your solutions.

Common Coding Platforms Used

Infosys frequently uses coding platforms such as HackerRank and Codility to conduct their online coding assessments. These platforms provide an interactive environment where you can write, compile, and test your code. It is highly recommended that you practise coding on these platforms to become familiar with their interface and environment before taking the actual test.

Time Constraints and Difficulty Levels

Infosys coding assessments typically include two to three coding problems, which must be solved within a time limit of 60 to 90 minutes. The difficulty level of the problems may vary, ranging from basic to advanced. It is crucial to manage your time effectively during the assessment to ensure that you have enough time to attempt all the questions.

The problems may involve topics such as arrays, strings, linked lists, trees, graphs, dynamic programming, recursion, and more. Being well-prepared in these topics will help you confidently tackle the coding assessment.

Infosys Coding Questions and Answers

To help you prepare for the Infosys coding assessments, we have compiled 20 common coding questions along with their solutions. These questions cover a wide range of topics, including arrays, strings, linked lists, stacks, queues, trees, graphs, dynamic programming, recursion, and other important topics. Let’s dive into each category and explore the questions and answers.

Infosys Coding Questions: Arrays and Strings

1) Array Reversal

Problem: Reverse an array of integers.

Solution: Use a two-pointer technique to swap elements from the start and end of the array.

python

def reverse_array(arr):

    start, end = 0, len(arr) – 1

    while start < end:

        arr[start], arr[end] = arr[end], arr[start]

        start += 1

        end -= 1

    return arr

2) String Palindrome Check

Problem: Check if a given string is a palindrome.

Solution: Compare the string with its reverse.

python

def is_palindrome(s):

    return s == s[::-1]

3) Array Rotation

Problem: Rotate an array to the right by k steps.

Solution: Rotate the array using slicing technique.

python

def rotate_array(arr, k):

    k %= len(arr)

    return arr[-k:] + arr[:-k]

4) Substring Search

Problem: Find all occurrences of a substring in a given string.

Solution: Use Python’s built-in find function to search for substrings.

python

def find_substring(s, sub):

    return [i for i in range(len(s)) if s.startswith(sub, i)]

5) Anagram Check

Problem: Check if two strings are anagrams of each other.

Solution: Sort both strings and compare them.

python

def are_anagrams(s1, s2):

    return sorted(s1) == sorted(s2)

Infosys Coding Questions: Linked Lists

6) Reverse a Singly Linked List

Problem: Reverse a singly linked list.

Solution: Use an iterative approach to reverse the links between nodes.

python

class ListNode:

    def __init__(self, value=0, next=None):

        self.value = value

        self.next = next

def reverse_linked_list(head):

    prev, curr = None, head

    while curr:

        next_temp = curr.next

        curr.next = prev

        prev = curr

        curr = next_temp

    return prev

7) Detect a Cycle in a Linked List

Problem: Check if a singly linked list has a cycle.

Solution: Use Floyd’s Cycle Detection algorithm (also known as the Tortoise and Hare algorithm).

python

def has_cycle(head):

    slow, fast = head, head

    while fast and fast.next:

        slow = slow.next

        fast = fast.next.next

        if slow == fast:

            return True

    return False

8) Merge Two Sorted Linked Lists

Problem: Merge two sorted linked lists into one sorted list.

Solution: Use a two-pointer technique to merge the two lists.

python

def merge_sorted_lists(l1, l2):

    dummy = ListNode()

    current = dummy

    while l1 and l2:

        if l1.value < l2.value:

            current.next = l1

            l1 = l1.next

        else:

            current.next = l2

            l2 = l2.next

        current = current.next

    current.next = l1 or l2

    return dummy.next

Infosys Coding Questions: Stacks and Queues

9) Implement Stack Using Array

Problem: Implement a basic stack using an array.

Solution: Use a list to implement push and pop operations.

python

class Stack:

    def __init__(self):

        self.stack = []

    def push(self, value):

        self.stack.append(value)

    def pop(self):

        return self.stack.pop() if self.stack else None

10) Parenthesis Balancing

Problem: Check if parentheses in a string are balanced.

Solution: Use a stack to match opening and closing parentheses.

python

def is_balanced(s):

    stack = []

    for char in s:

        if char in “({[“:

            stack.append(char)

        else:

            if not stack or {‘)’:'(‘, ‘]’:'[‘, ‘}’:'{‘}[char] != stack.pop():

                return False

    return not stack

Infosys Coding Questions: Trees

11) Inorder Traversal of Binary Tree

Problem: Perform inorder traversal of a binary tree.

Solution: Use recursion to traverse the tree in the order: left subtree, root, right subtree.

python

def inorder_traversal(root):

    return inorder_traversal(root.left) + [root.val] + inorder_traversal(root.right) if root else []

12) Binary Search Tree Insertion

Problem: Insert a value into a binary search tree.

Solution: Recursively find the correct position to insert the new value.

python

def insert_into_bst(root, value):

    if not root:

        return TreeNode(value)

    if value < root.val:

        root.left = insert_into_bst(root.left, value)

    else:

        root.right = insert_into_bst(root.right, value)

    return root

Infosys Coding Questions: Graphs

13) Breadth-First Search (BFS)

Problem: Perform Breadth-First Search (BFS) on a graph.

Solution: Use a queue to traverse the graph level by level.

python

from collections import deque

def bfs(graph, start):

    visited = set()

    queue = deque([start])

    while queue:

        node = queue.popleft()

        if node not in visited:

            visited.add(node)

            queue.extend(graph[node] – visited)

    return visited

14) Depth-First Search (DFS)

Problem: Perform Depth-First Search (DFS) on a graph.

Solution: Use recursion or a stack to traverse the graph in a depth-wise manner.

python

def dfs(graph, start, visited=None):

    if visited is None:

        visited = set()

    visited.add(start)

    for next_node in graph[start] – visited:

        dfs(graph, next_node, visited)

    return visited

15) Dijkstra’s Shortest Path Algorithm

Problem: Find the shortest path in a graph using Dijkstra’s algorithm.

Solution: Use a priority queue to keep track of the shortest paths.

python

import heapq

def dijkstra(graph, start):

    distances = {node: float(‘inf’) for node in graph}

    distances[start] = 0

    pq = [(0, start)]

    while pq:

        curr_dist, node = heapq.heappop(pq)

        if curr_dist > distances[node]:

            continue

        for neighbor, weight in graph[node]:

            distance = curr_dist + weight

            if distance < distances[neighbor]:

                distances[neighbor] = distance

                heapq.heappush(pq, (distance, neighbor))

    return distances

Infosys Coding Questions: Dynamic Programming

16) Fibonacci Series Using Dynamic Programming

Problem: Find the nth Fibonacci number using dynamic programming.

Solution: Use memoization or tabulation to store previously computed results.

python

def fibonacci(n, memo={}):

    if n in memo:

        return memo[n]

    if n <= 1:

        return n

    memo[n] = fibonacci(n-1, memo) + fibonacci(n-2, memo)

    return memo[n]

17) 0/1 Knapsack Problem

Problem: Solve the 0/1 knapsack problem using dynamic programming.

Solution: Use a table to store the maximum values for sub-problems based on item weights and values.

python

def knapsack(weights, values, capacity):

    n = len(weights)

    dp = [[0] * (capacity + 1) for _ in range(n + 1)]

    for i in range(1, n + 1):

        for w in range(1, capacity + 1):

            if weights[i – 1] <= w:

                dp[i][w] = max(dp[i – 1][w], dp[i – 1][w – weights[i – 1]] + values[i – 1])

            else:

                dp[i][w] = dp[i – 1][w]

    return dp[n][capacity]

Infosys Coding Questions: Recursion

18) Tower of Hanoi

Problem: Solve the Tower of Hanoi problem using recursion.

Solution: Move disks between rods using recursive steps.

python

def tower_of_hanoi(n, source, target, auxiliary):

    if n == 1:

        print(f”Move disk 1 from {source} to {target}”)

        return

    tower_of_hanoi(n – 1, source, auxiliary, target)

    print(f”Move disk {n} from {source} to {target}”)

    tower_of_hanoi(n – 1, auxiliary, target, source)

19) Recursive Factorial

Problem: Find the factorial of a number using recursion.

Solution: Multiply the number by the factorial of the previous number.

python

def factorial(n):

    if n == 0:

        return 1

    return n * factorial(n – 1)

Infosys Coding Questions: Other Topics

20) Bitwise AND of Numbers Range

Problem: Find the bitwise AND of all numbers in a range.

Solution: Use bitwise operations to narrow down the range and find the result.

python

def range_bitwise_and(m, n):

    shift = 0

    while m != n:

        m >>= 1

        n >>= 1

        shift += 1

    return m << shift

Infosys Coding Questions: Tips and Tricks

Preparing for Infosys coding assessments requires more than just knowledge of coding concepts. Here are some practical tips and strategies to help you succeed in your coding test and technical interviews:

tips tricks infosys coding assessments

1) Effective Problem-Solving Strategies

When approaching coding problems, break them down into smaller, more manageable parts. Start by understanding the problem statement and writing down any observations. From there, you can devise a plan to solve the problem step by step. It’s important to think about edge cases and test your solution against them.

2) Time Management Techniques

Time management is crucial during coding assessments. You will likely face multiple problems with varying levels of difficulty. Prioritise solving the easier problems first to secure points, and then move on to more complex problems. Don’t spend too much time on a single problem if you’re stuck—move on and return to it later if you have time.

3) Code Optimization and Efficiency

Many coding problems have time and space constraints. Focus on writing efficient code that runs within the given limits. Choose the appropriate data structures and algorithms based on the problem requirements. For example, use binary search when dealing with sorted arrays, or dynamic programming to avoid redundant calculations.

4) Common Coding Mistakes to Avoid

Avoid common mistakes such as:

  • Off-by-one errors (e.g., incorrect array indexing)
  • Forgetting to initialise variables
  • Failing to handle edge cases
  • Using inefficient algorithms that lead to timeouts

Double-check your code for these mistakes before submitting it.

5) Practise on Coding Platforms

Familiarise yourself with coding platforms such as HackerRank, Codility, and iScalePro. These platforms simulate real coding assessment environments and provide you with valuable practice. Focus on solving problems from past Infosys coding assessments and similar challenges to improve your problem-solving skills.

Conclusion

A strong foundation in coding is essential to succeed in the Infosys recruitment process. Mastering key programming languages like Java, Python, and C++, along with data structures, algorithms, and problem-solving techniques, will help you excel in the coding assessments. By practising the coding questions provided in this article and following the tips shared, you can enhance your chances of securing a job at Infosys.

Remember, preparation is key—dedicate time to understanding the concepts, practising coding problems, and familiarising yourself with the coding platforms used by Infosys. With determination and consistent effort, you’ll be well-prepared to crack the Infosys coding assessments and move forward in the recruitment process.

Infosys Coding Interview FAQs

1) Are Infosys coding questions hard?

Infosys coding questions are not as hard as those from some other tech giants. However, they can still be challenging, especially if you are not well-prepared. The questions are usually based on common data structures and algorithms.

2) Is coding important for Infosys?

Yes, coding is important for Infosys. The company is a leading global technology services and consulting firm. They work on complex projects that require strong coding skills.

3) How to pass Infosys online test?

Here are some tips to help you pass the Infosys online test:

  • Practice coding regularly: The more you practice, the better you will become at coding.
  • Learn common data structures and algorithms: These are the building blocks of coding.
  • Solve practice problems: There are many websites and platforms where you can find practice problems.
  • Time management: Make sure you can solve the problems within the allotted time.

4) Which company has the hardest coding interview questions?

There is no definitive answer to this question. The difficulty of coding interview questions varies from company to company. However, some companies are known for having particularly challenging questions, such as Google, Facebook, and Amazon.

Click below to simplify hiring 👇

Scroll to Top