← Infosys Interview Insights

Infosys·Software Engineer·Online Assessment (OA)·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Three algorithmic questions for Infosys, ranging from a warm-up array problem to something that made me genuinely pause. The difficulty ramp was steep and the last one felt a bit unfair for the context.

Questions Asked (3)

Q1

Given a mountain array (elements first increase then decrease), find the maximum element.

Algorithms & Data Structures
Author's notes

Pretty standard warmup.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use binary search to find the peak element by comparing mid with its neighbors. If mid is less than the next element, the peak lies to the right; otherwise, it lies to the left. This achieves O(log n) time complexity.

Pro tip: Mention that this approach is optimal for large arrays and handles edge cases like single-element or strictly increasing/decreasing arrays. Also, clarify that the array is guaranteed to be a mountain array, so no need to check for invalid inputs.

1. Clarify the problem

Confirm that the array is a mountain array (strictly increasing then strictly decreasing) and that the maximum element is the peak. Ask if there are any constraints on array size or element values.

2. Choose the algorithm

Explain that a linear scan would work but is O(n). Propose binary search for O(log n) efficiency, which is preferred for large arrays.

3. Define the binary search logic

Set low = 0, high = n-1. While low < high, compute mid. If arr[mid] < arr[mid+1], the peak is to the right, so low = mid+1; else, the peak is at mid or to the left, so high = mid.

4. Handle edge cases

Discuss cases like array of size 1, peak at the beginning or end, and ensure the loop terminates correctly. Return arr[low] as the peak.

5. Analyze complexity

State that time complexity is O(log n) and space complexity is O(1). Compare with linear search O(n) to highlight efficiency.

Key Points to Mention

  • Binary search approach for O(log n) time complexity
  • Comparison of mid with mid+1 to decide search direction
  • Handling of edge cases (single element, peak at boundaries)
  • Space complexity O(1) using iterative binary search
  • Assumption that input is a valid mountain array
  • Avoiding integer overflow when computing mid (use low + (high - low)/2)

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Count the number of ways to reach a target sum using three given numbers, where you cannot use the same number twice consecutively.

Algorithms & Data Structures
Author's notes

This one tripped me up more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints (e.g., numbers can be reused, order matters, target sum range) and then propose a dynamic programming solution that tracks the last used number to enforce the no-consecutive rule. Explain the state definition, recurrence relation, and how to optimize space if needed.

Pro tip: Mention that the DP state can be reduced to O(target) space by keeping only the previous step's counts, and discuss how the solution changes if the numbers are not distinct or if the target is very large.

1. Clarify the problem

Ask clarifying questions: Are the three numbers distinct? Can each number be used multiple times? Does order of addition matter? What is the range of the target sum?

2. Define the DP state

Define dp[i][j] as the number of ways to reach sum i where the last used number is j (or a state indicating no last number). Initialize dp[0][none] = 1.

3. Formulate recurrence

For each sum i from 1 to target, and for each number j, if j != last, add dp[i-j][last] to dp[i][j]. Handle base cases and avoid double-counting.

4. Compute and return result

Iterate through sums and numbers in increasing order, then sum dp[target][j] over all j to get the total number of valid sequences.

5. Analyze complexity and optimize

State time complexity O(target * 3) and space O(target * 3). Discuss reducing space to O(target) by keeping only the previous sum's states.

Key Points to Mention

  • Dynamic programming with state tracking the last used number
  • Time and space complexity analysis
  • Handling base cases (e.g., target = 0)
  • Edge cases: target smaller than any number, negative numbers (if allowed)
  • Potential for space optimization using rolling arrays
  • Comparison with recursive backtracking and memoization

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Find the longest common substring between two strings where at most one character mismatch is allowed, and the mismatched characters must belong to the same class (both vowels or both consonants).

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Threw me completely.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then propose a dynamic programming solution that tracks the length of the longest common substring ending at each position, along with the number of mismatches and the class of the mismatched character. Optimize space to O(n) and discuss time complexity O(m*n).

Pro tip: Demonstrate awareness of trade-offs: mention that while DP is straightforward, a suffix automaton or rolling hash with binary search could be more efficient for large inputs, but DP is acceptable for an interview setting.

1. Clarify Requirements and Edge Cases

Ask about input size, character set, definition of vowels/consonants, and whether the mismatch can be at any position. Confirm that the substring must be contiguous.

2. Define DP State and Transitions

Define dp[i][j] as the length of the longest common substring ending at s1[i] and s2[j] with at most one allowed mismatch. Track the mismatch class (vowel/consonant) to enforce the condition.

3. Implement and Optimize Space

Fill the DP table row by row, using only two rows to save space. Update the maximum length and handle the mismatch condition carefully.

4. Analyze Complexity and Discuss Alternatives

State time O(m*n) and space O(n). Mention that for very large strings, suffix automaton or binary search with rolling hash could be more efficient, but DP is simpler and sufficient for most interviews.

5. Test with Examples

Walk through a few examples, including cases with no mismatch, one valid mismatch, and one invalid mismatch (different classes), to verify correctness.

Key Points to Mention

  • Dynamic programming state definition and transition
  • Handling the mismatch condition: same class (both vowels or both consonants)
  • Space optimization using rolling arrays
  • Time and space complexity analysis
  • Edge cases: empty strings, no common substring, multiple mismatches
  • Alternative approaches: suffix automaton, rolling hash with binary search

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.