Infosys Coding Questions for SP and DSE (With Answers)

Prepare for the Infosys SP and DSE coding rounds with the most frequently asked coding questions, detailed solutions, and expert preparation tips to ace your interview.

Infosys SP and DSE Coding Questions with Answers

The Infosys Specialist Programmer (SP) and Digital Specialist Engineer (DSE) coding rounds are designed to assess your problem-solving skills, coding proficiency, and understanding of data structures and algorithms. 

Practicing the right coding questions is one of the most effective ways to improve your performance in these competitive assessments.

In this guide, we've compiled some of the most frequently asked Infosys SP and DSE coding questions, along with their approaches and sample solutions. 

If you're looking for a comprehensive preparation roadmap, be sure to check out our Infosys SP & DSE Interview Guide 2026, which covers the latest selection process, interview rounds, eligibility criteria, and expert preparation tips.

Most Asked Infosys SP and DSE Coding Questions 

This is the section that matters most. Here are the actual topic areas and example problems drawn from Infosys coding interview questions and answers from previous years.

Learn to Code Under Pressure: Time management is key. The Ace Coding Interviews free course provides a structured framework for tackling common interview patterns effectively. 

Additionally, watching a professional breakdown of problems on YouTube, such as Common coding interview problems | Coding Interview Questions & Answers, visually reinforces how to approach unseen questions methodically by explaining the logic step by step before touching the keyboard.

Easy Level Coding Questions

1. Kadane's Algorithm  Maximum Subarray Sum

One of the most frequently appearing easy questions.

Problem: Given an array of integers, find the contiguous subarray with the largest sum.

Example:

python
Input:  [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output: 6
Explanation: [4, -1, 2, 1] has the maximum sum = 6

Approach: Maintain a running sum. If the running sum goes negative, reset it to zero. Track the maximum seen so far.

python
def maxSubArray(nums):
    max_sum = nums[]
    current_sum = nums[]
    for num in nums[1:]:
        current_sum = max(num, current_sum + num)
        max_sum = max(max_sum, current_sum)
    return max_sum

2. Next Greater Element

Problem: Given an array, for each element return the first greater element to its right. Return -1 if no such element exists.

Example:

python
Input:  [1, 3, 2]
Output: [3, -1, -1]

Approach: Use a monotonic stack. Traverse right to left and maintain a decreasing stack.

python
def nextGreaterElement(nums):
    result = [-1] * len(nums)
    stack = []
    for i in range(len(nums) - 1, -1, -1):
        while len(stack) >  and stack[-1] <= nums[i]:
            stack.pop()
        if stack:
            result[i] = stack[-1]
        stack.append(nums[i])
    return result

3. Rotate Array by K Positions

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

Example:

python
Input:  [1, 2, 3, 4, 5, 6, 7], k = 3
Output: [5, 6, 7, 1, 2, 3, 4]

Approach: Reverse the entire array, then reverse the first k elements, then reverse the remaining n-k elements. Time complexity O(n), Space O(1).

python
def rotateArray(nums, k):
    n = len(nums)
    k = k % n  # Handle cases where k > n

    def reverse(left, right):
        while left < right:
            nums[left], nums[right] = nums[right], nums[left]
            left += 1
            right -= 1

    reverse(, n - 1)   # Step 1: Reverse entire array
    reverse(, k - 1)   # Step 2: Reverse first k elements
    reverse(k, n - 1)   # Step 3: Reverse remaining elements
    return nums

# Test
print(rotateArray([1, 2, 3, 4, 5, 6, 7], 3))
# Output: [5, 6, 7, 1, 2, 3, 4]

Build Your Core Competency: Before tackling advanced development, ensure your foundations are rock solid with the Programming Basics free course. This beginner-friendly module on Great Learning Academy helps you grasp core programming logic, syntax, and fundamental coding paradigms through self-paced video lectures, culminating in a free certificate of completion. 

Additionally, if you are eyeing backend DSE roles, the Python Foundations course is an excellent starting point to understand variables, loops, and basic Python syntax from scratch.

Medium Level Coding Questions

4. Longest Common Subsequence (Dynamic Programming)

One of the most commonly asked medium-level Infosys SP and DSE coding questions.

Problem: Given two strings, find the length of their longest common subsequence.

Example:

python
Input:  s1 = "ABCBDAB", s2 = "BDCAB"
Output: 4
Explanation: "BCAB" is the LCS

Approach: Classic 2D DP. dp[i][j] represents LCS of first i characters of s1 and first j characters of s2.

python
def lcs(s1, s2):
    m, n = len(s1), len(s2)
    dp = [[] * (n + 1) for _ in range(m + 1)]
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if s1[i-1] == s2[j-1]:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])
    return dp[m][n]

5. Number of Islands (BFS/DFS on Grid)

Problem: Given a 2D grid of '1's (land) and '0's (water), count the number of islands. An island is formed by connecting adjacent lands horizontally or vertically.

Example:

python
Input:
11110
11010
11000
00000
Output: 1

Approach: Use BFS or DFS. Whenever you find a '1', trigger a BFS to mark all connected land cells as visited. Increment the island count each time you start a new BFS.

python
from collections import deque

def numIslands(grid):
    if not grid:
        return 

    rows, cols = len(grid), len(grid[])
    count = 

    def bfs(r, c):
        queue = deque([(r, c)])
        grid[r] = '0'  # Mark as visited
        while queue:
            row, col = queue.popleft()
            for dr, dc in [(1,), (-1,), (,1), (,-1)]:
                nr, nc = row + dr, col + dc
                if  <= nr < rows and  <= nc < cols and grid[nr][nc] == '1':
                    grid[nr][nc] = '0'
                    queue.append((nr, nc))

    for r in range(rows):
        for c in range(cols):
            if grid[r] == '1':
                bfs(r, c)
                count += 1

    return count

# Test
grid = [
    ['1','1','1','1','0'],
    ['1','1','0','1','0'],
    ['1','1','0','0','0'],
    ['0','0','0','0','0']
]
print(numIslands(grid))
# Output: 1

6. Coin Change Problem (Minimum Coins)

Problem: Given coin denominations and a target amount, find the minimum number of coins needed to make the amount. Return -1 if not possible.

Example:

python
Input:  coins = [1, 5, 6, 9], amount = 11
Output: 2
Explanation: 5 + 6 = 11

Approach: Bottom-up DP. dp[i] = minimum coins to make amount i. For each amount, try all coins and take the minimum.

python
def coinChange(coins, amount):
    dp = [float('inf')] * (amount + 1)
    dp[] =   # Base case: 0 coins needed to make amount 0

    for i in range(1, amount + 1):
        for coin in coins:
            if coin <= i:
                dp[i] = min(dp[i], dp[i - coin] + 1)

    return dp[amount] if dp[amount] != float('inf') else -1

# Test
print(coinChange([1, 5, 6, 9], 11))
# Output: 2  (5 + 6 = 11)

print(coinChange([2], 3))
# Output: -1  (not possible)

Master the Logic: To consistently hit the SP threshold, enroll in the free Competitive Programming Course by Great Learning Academy. This course systematically teaches you how to optimize your code to meet strict time complexity constraints, a crucial skill for medium-to-hard assessment questions. 

Hard Level Coding Questions

7. Maximize Total Value by Packing Gifts into K Boxes (DP + Sliding Window)

This is a representative hard-level problem that has appeared in Infosys specialist programmer coding questions.

Problem: You have N gifts of different types. Pack them into exactly K boxes (consecutive subarrays) such that each box's value equals the number of distinct gift types in it. Maximize total value.

Example:

python
Input:  N=6, K=3, gifts=[1,1,2,2,3,3]
Output: 4
Explanation: [1]=1, [1,2,2]=2, [3,3]=1 → total = 4

Approach: DP with a sliding window and a HashMap to track distinct elements. dp[i][j] = maximum value of packing the first j gifts into i boxes. Use a two-pointer or sliding window within each DP transition.

python
def maximizeGifts(N, K, gifts):
    # dp[i][j] = max value packing first j gifts into i boxes
    dp = [[-float('inf')] * (N + 1) for _ in range(K + 1)]
    dp[][] = 

    for i in range(1, K + 1):
        for j in range(i, N + 1):
            freq = {}
            distinct = 
            # Try all starting positions for the i-th box ending at j
            for start in range(j, i - 1, -1):
                gift = gifts[start - 1]
                freq[gift] = freq.get(gift, ) + 1
                if freq[gift] == 1:
                    distinct += 1
                if dp[i - 1][start - 1] != -float('inf'):
                    dp[i][j] = max(dp[i][j], dp[i - 1][start - 1] + distinct)

    return max(dp[K])

# Test
print(maximizeGifts(6, 3, [1, 1, 2, 2, 3, 3]))
# Output: 4  ([1]=1, [1,2,2]=2, [3,3]=1 → total=4)

8. Trapping Rain Water

Problem: Given an elevation map represented by an array, compute how much water it can trap after raining.

Example:

python
Input:  [,1,,2,1,,1,3,2,1,2,1]
Output: 6

Approach: Two-pointer technique. Maintain left_max and right_max. At each position, water trapped = min(left_max, right_max) - height[i].

python
def trap(height):
    if not height:
        return 

    left, right = , len(height) - 1
    left_max, right_max = , 
    water = 

    while left < right:
        if height[left] < height[right]:
            if height[left] >= left_max:
                left_max = height[left]
            else:
                water += left_max - height[left]
            left += 1
        else:
            if height[right] >= right_max:
                right_max = height[right]
            else:
                water += right_max - height[right]
            right -= 1

    return water

# Test
print(trap([,1,,2,1,,1,3,2,1,2,1]))
# Output: 6

print(trap([4,2,,3,2,5]))
# Output: 9

9. Longest Increasing Path in a Matrix (DFS + Memoization)

Problem: Given an m x n integer matrix, return the length of the longest increasing path.

Approach: DFS from each cell with memoization. From each cell, try all 4 directions and move only if the next value is strictly greater.

python
def longestIncreasingPath(matrix):
    if not matrix or not matrix[]:
        return 

    rows, cols = len(matrix), len(matrix[])
    memo = {}

    def dfs(r, c):
        if (r, c) in memo:
            return memo[(r, c)]

        best = 1  # At minimum, the cell itself is a path of length 1
        for dr, dc in [(1,), (-1,), (,1), (,-1)]:
            nr, nc = r + dr, c + dc
            if  <= nr < rows and  <= nc < cols and matrix[nr][nc] > matrix[r]:
                best = max(best, 1 + dfs(nr, nc))

        memo[(r, c)] = best
        return best

    return max(dfs(r, c) for r in range(rows) for c in range(cols))

# Test
matrix1 = [
    [9, 9, 4],
    [6, 6, 8],
    [2, 1, 1]
]
print(longestIncreasingPath(matrix1))
# Output: 4  (path: 1 → 2 → 6 → 9)

matrix2 = [
    [3, 4, 5],
    [3, 2, 6],
    [2, 2, 1]
]
print(longestIncreasingPath(matrix2))
# Output: 4  (path: 3 → 4 → 5 → 6)

Conclusion

Success in the Infosys SP and DSE coding rounds comes down to consistent practice, a strong understanding of data structures and algorithms, and the ability to solve problems efficiently under time constraints. 

By working through the coding questions and approaches covered in this guide, you'll build the confidence and problem-solving skills needed to perform well in the assessment. 

Remember to focus not only on finding the correct solution but also on writing optimized, clean code and analyzing its time and space complexity.

To complete your preparation, don't miss our Infosys SP and DSE Interview Guide 2026, which covers everything you need to know about the selection process, interview rounds, eligibility, and expert preparation tips.

Frequently Asked Questions (FAQs)

1. What coding questions are asked in the Infosys SP and DSE interview?

The Infosys SP and DSE coding interviews typically include problems on arrays, strings, linked lists, stacks, queues, trees, graphs, dynamic programming, recursion, greedy algorithms, hashing, and sliding window techniques. The company focuses on evaluating your problem-solving ability, coding efficiency, and understanding of data structures and algorithms.

2. Is the Infosys Specialist Programmer (SP) coding round difficult?

Yes, the Infosys Specialist Programmer (SP) coding round is considered more challenging than the standard recruitment process. Candidates are expected to solve medium- to hard-level coding problems within a limited time while writing optimized and error-free code.

3. Which programming language should I use for the Infosys coding interview?

Infosys supports multiple programming languages, including C, C++, Java, and Python. You should choose the language you are most comfortable with, as familiarity allows you to solve problems more efficiently and avoid syntax-related mistakes during the assessment.

4. What topics should I prepare for the Infosys DSE coding test?

To perform well in the Infosys DSE coding test, you should thoroughly prepare data structures and algorithms, particularly arrays, strings, linked lists, trees, graphs, dynamic programming, recursion, greedy algorithms, binary search, hashing, and graph traversal techniques such as BFS and DFS. Regular practice on coding platforms can help strengthen these concepts.

5. How many coding questions are asked in the Infosys SP assessment?

The number of coding questions may vary by recruitment cycle, but candidates are generally asked to solve two or three coding problems. These questions usually progress from medium to hard difficulty and test both correctness and optimization.

6. Is Dynamic Programming important for Infosys SP interviews?

Yes, Dynamic Programming is one of the most important topics for the Infosys Specialist Programmer interview. Questions based on Longest Common Subsequence, Coin Change, Knapsack, Matrix DP, and other optimization problems frequently appear in coding assessments.

7. How can I crack the Infosys SP and DSE coding round?

The best way to crack the Infosys SP and DSE coding round is to practice coding questions consistently, master core DSA concepts, solve previous-year interview problems, participate in timed coding contests, and learn common interview patterns. Along with coding practice, reviewing your solutions for time and space complexity is equally important.

Avatar photo
Great Learning Editorial Team
The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.

Go Beyond Learning. Get Job-Ready.

Build in-demand skills for today's jobs with free expert-led courses and practical AI tools.

Explore All Courses
Scroll to Top