Larsen & Toubro (L&T) Previous Year Coding Questions

Larsen & Toubro (L&T) is one of India’s leading engineering and technology-driven conglomerates, with its IT arm LTIMindtree (formerly LTI) actively hiring for roles like Graduate Engineer Trainee (GET), Software Engineer, and Associate Engineer.

For tech roles, the recruitment process usually starts with an Online Assessment (OA) that tests core programming, data structures, and problem-solving skills, followed by technical and HR interview rounds. The coding questions are designed to assess not only your ability to write correct code but also your approach, efficiency, and logical thinking.

From arrays, strings, and linked lists to trees, matrices, and graph problems, the questions asked in L&T / LTIMindtree drives are often of easy-to-medium difficulty, making them ideal for freshers and early-career candidates to prepare with.

Hiring Process

  1. Online Assessment (OA):
    • Format: 1-2 coding questions, 45-60 minutes.
    • Topics: Arrays, strings, linked lists, matrices, trees, graphs, basic math/logic.
    • Languages Allowed: C++, Java, Python.
    • Difficulty: Easy to medium, with partial marks for passing test cases.
    • Platform: Often conducted on platforms like AMCAT or in-house systems.
  2. Technical Interview:
    • Live coding or explaining solutions to OA problems.
    • Questions on data structures, algorithms, and project experience.
    • May include system design or DBMS for IT roles.
  3. HR Interview:
    • Behavioral questions, communication skills, and fit for company culture.
    • May involve basic technical queries for non-IT roles.
  4. Other Rounds (varies by role):
    • Aptitude tests (quantitative, logical reasoning, verbal).
    • Group discussions for some drives.

Preparation Resources

Previous Year Coding Questions

Array Manipulation

1. Sort First K Elements Ascending, Rest Descending

Problem Statement: Given an array of N integers and an integer K, rearrange the array such that the first K elements are sorted in ascending order, and the remaining N-K elements are sorted in descending order. Perform the rearrangement in-place if possible.
Input: Array of integers, size N, integer K (1 ≤ K ≤ N).
Output: Modified array with first K elements in ascending order and rest in descending order.
Constraints: 1 ≤ N ≤ 10^5, elements in [-10^9, 10^9].
Example:

Input: arr = [5, 2, 9, 1, 7, 6], K = 3
Output: [1, 2, 5, 9, 7, 6]

2. Maximum Product Subarray

Problem Statement: Given an array of integers (positive, negative, or zero), find the contiguous subarray with the maximum product. Return the maximum product value. Handle negative numbers and zeros.
Input: Array of integers, size N.
Output: Maximum product of any contiguous subarray.
Constraints: 1 ≤ N ≤ 10^5, elements in [-10^4, 10^4].
Example:

Input: arr = [2, 3, -2, 4]
Output: 6 (subarray [2, 3])

3. Maximum Subarray Sum

Problem Statement: Given an array of integers (positive or negative), find the contiguous subarray with the maximum sum. Return the maximum sum. If all numbers are negative, return the largest single element.
Input: Array of integers, size N.
Output: Maximum sum of any contiguous subarray.
Constraints: 1 ≤ N ≤ 10^5, elements in [-10^6, 10^6].
Example:

Input: arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output: 6 (subarray [4, -1, 2, 1])

4. Triplets with Zero Sum

Problem Statement: Given an array of integers, determine if there exists a triplet whose sum is zero. Print "Yes" if such a triplet exists, else "No".
Input: Array of integers, size N.
Output: "Yes" or "No".
Constraints: 1 ≤ N ≤ 10^3, elements in [-10^5, 10^5].
Example:

Input: arr = [0, -1, 2, -3, 1]
Output: Yes (triplet: -1, 2, -1)

String Problems

5. Palindrome Check

Problem Statement: Given a string, check if it is a palindrome after ignoring case, spaces, and non-alphanumeric characters. Return true if it is a palindrome, false otherwise.
Input: A string S.
Output: True or False.
Constraints: 1 ≤ |S| ≤ 10^5, string contains letters, digits, spaces, and special characters.
Example:

Input: S = "A man, a plan, a canal: Panama"
Output: True

6. Longest Even-Length Substring with Equal Half Sums

Problem Statement: Given a string of digits, find the length of the longest even-length substring where the sum of digits in the first half equals the sum of digits in the second half. Return 0 if no such substring exists.
Input: String S of digits.
Output: Length of the longest valid substring.
Constraints: 1 ≤ |S| ≤ 10^5, S contains only digits [0-9].
Example:

Input: S = "123123"
Output: 6 (substring "123123", first half sum = 1+2+3 = 6, second half = 1+2+3 = 6)

7. Smallest Window with All Characters

Problem Statement: Given two strings S and T, find the smallest substring in S that contains all characters of T (including duplicates). Return an empty string if no such substring exists.
Input: Strings S and T.
Output: Smallest substring of S containing all chars of T, or "".
Constraints: 1 ≤ |S|, |T| ≤ 10^5, S and T contain lowercase letters.
Example:

Input: S = "ADOBECODEBANC", T = "ABC"
Output: "BANC"

8. Pattern Matching with Wildcards

Problem Statement: Given a string S and a pattern P containing wildcards ( for any sequence, ? for any single character), check if S matches P. Return true if it matches, false otherwise.
Input: String S, pattern P.
Output: True or False.
Constraints: 1 ≤ |S|, |P| ≤ 10^5, S contains lowercase letters, P contains lowercase letters,
, ?.
Example:

Input: S = "aa", P = "a*"
Output: True

Linked List Problems

9. Merge Two Sorted Linked Lists

Problem Statement: Given two sorted linked lists, merge them into a single sorted linked list. Return the head of the merged list.
Input: Heads of two sorted linked lists (non-decreasing order).
Output: Head of the merged sorted linked list.
Constraints: 0 ≤ length of lists ≤ 10^4, node values in [-10^5, 10^5].
Example:

Input: list1 = 1->3->5, list2 = 2->4->6
Output: 1->2->3->4->5->6

10. Reverse Linked List in Groups of K

Problem Statement: Given a linked list and an integer K, reverse every K nodes in the list. If the remaining nodes are less than K, leave them as is. Return the head of the modified list.
Input: Head of linked list, integer K.
Output: Head of modified list.
Constraints: 1 ≤ K ≤ length of list ≤ 10^4, node values in [-10^5, 10^5].
Example:

Input: list = 1->2->3->4->5, K = 2
Output: 2->1->4->3->5

11. Find Middle Element of Linked List

Problem Statement: Given a singly linked list, find the middle node. If the list has an even number of nodes, return the second middle node.
Input: Head of linked list.
Output: Middle node’s value or reference.
Constraints: 1 ≤ length of list ≤ 10^5, node values in [-10^5, 10^5].
Example:

Input: list = 1->2->3->4->5
Output: 3

12. Detect and Remove Loop in Linked List

Problem Statement: Given a linked list, detect if it has a cycle. If a cycle exists, find the starting node of the cycle and remove it. Return the head of the modified list.
Input: Head of linked list.
Output: Head of list with cycle removed (or original head if no cycle).
Constraints: 0 ≤ length of list ≤ 10^4, node values in [-10^5, 10^5].
Example:

Input: list = 1->2->3->4->2 (cycle at 2)
Output: 1->2->3->4

Matrix/Grid Problems

13. Rotate Matrix by 90 Degrees

Problem Statement: Given an N x N matrix of integers, rotate it 90 degrees clockwise in-place. Do not use extra space beyond O(1).
Input: N x N matrix.
Output: Rotated matrix (in-place).
Constraints: 1 ≤ N ≤ 100, elements in [-10^3, 10^3].
Example:

Input: [[1,2,3],[4,5,6],[7,8,9]]
Output: [[7,4,1],[8,5,2],[9,6,3]]

14. Maximum Rectangular Area in Histogram

Problem Statement: Given an array of integers representing heights of bars in a histogram, find the area of the largest rectangle that can be formed.
Input: Array of integers (heights), size N.
Output: Maximum area of rectangle.
Constraints: 1 ≤ N ≤ 10^5, heights in [0, 10^9].
Example:

Input: heights = [2,1,5,6,2,3]
Output: 10 (rectangle with height 5, width 2)

15. Search in Rotated Sorted Array

Problem Statement: Given a sorted array rotated at some pivot and a target value, find if the target exists in the array. Return its index or -1 if not found.
Input: Array of integers, size N, target integer.
Output: Index of target or -1.
Constraints: 1 ≤ N ≤ 10^5, elements in [-10^4, 10^4].
Example:

Input: arr = [4,5,6,7,0,1,2], target = 0
Output: 4

Tree/Graph Problems

16. Check if Binary Tree is BST

Problem Statement: Given a binary tree, determine if it is a valid binary search tree (BST). Each node’s value must be greater than all nodes in its left subtree and less than all nodes in its right subtree.
Input: Root of binary tree.
Output: True if BST, False otherwise.
Constraints: 1 ≤ number of nodes ≤ 10^4, node values in [-10^9, 10^9].
Example:

Input: tree = [2,1,3]
Output: True
Input: tree = [5,1,4,null,null,3,6]
Output: False

17. Level Order Traversal of Binary Tree

Problem Statement: Given a binary tree, print the values of its nodes level by level, from left to right. Each level should be printed as a list or on a new line.
Input: Root of binary tree.
Output: List of node values by level.
Constraints: 1 ≤ number of nodes ≤ 10^4, node values in [-10^5, 10^5].
Example:

Input: tree = [3,9,20,null,null,15,7]
Output: [[3],[9,20],[15,7]]

18. Number of Islands

Problem Statement: Given a 2D grid of '1's (land) and '0's (water), count the number of islands. An island is a group of '1's connected vertically or horizontally.
Input: M x N grid of characters ('1' or '0').
Output: Number of islands.
Constraints: 1 ≤ M, N ≤ 300, grid contains only '1' or '0'.
Example:

Input: grid = [["1","1","0"],["1","0","0"],["0","0","1"]]
Output: 2

Miscellaneous

19. Fibonacci Series

Problem Statement: Given an integer N, print the Fibonacci series up to the Nth term, or find the Nth Fibonacci number (starting with 0, 1).
Input: Integer N.
Output: Nth Fibonacci number or series up to N terms.
Constraints: 1 ≤ N ≤ 10^3.
Example:

Input: N = 5
Output: 0,1,1,2,3 or 3 (for Nth number)

20. Prime Number Check

Problem Statement: Given an integer N, determine if it is a prime number. A prime number is divisible only by 1 and itself.
Input: Integer N.
Output: "Yes" if prime, "No" otherwise.
Constraints: 1 ≤ N ≤ 10^9.
Example:

Input: N = 17
Output: Yes
Input: N = 4
Output: No

21. Swap Two Numbers Without Temporary Variable

Problem Statement: Given two integers A and B, swap their values without using a temporary variable. Print the swapped values.
Input: Two integers A, B.
Output: Swapped values of A and B.
Constraints: -10^9 ≤ A, B ≤ 10^9.
Example:

Input: A = 5, B = 10
Output: A = 10, B = 5

22. Greatest of Three Numbers

Problem Statement: Given three integers A, B, and C, find the largest among them.
Input: Three integers A, B, C.
Output: The largest integer.
Constraints: -10^9 ≤ A, B, C ≤ 10^9.
Example:

Input: A = 5, B = 12, C = 8
Output: 12

Join Telegram group for more resources & discussions!

🧰 Useful Resources for Your Placement Prep

Explore previous year questions from top companies to boost your placement prep: