Skip to content

L&T Coding Questions - DSA Problems & Solutions

Practice L&T placement paper coding questions with detailed solutions. Access L&T OA coding problems in C++, Java, Python.

This page contains L&T coding questions from L&T OA placement papers with detailed solutions.

L&T OA Coding Section:

  • Problems: 2-3 coding problems
  • Time: 90 minutes
  • Languages: C++, Java, Python
Q1: Schedule engineering projects with dependencies using topological sort.

Solution (Java):

public List<String> scheduleProjects(Map<String, List<String>> dependencies) {
Map<String, Integer> inDegree = new HashMap<>();
Map<String, List<String>> graph = new HashMap<>();
// Build graph and calculate in-degrees
for (String project : dependencies.keySet()) {
inDegree.putIfAbsent(project, 0);
for (String dep : dependencies.get(project)) {
graph.putIfAbsent(dep, new ArrayList<>()).add(project);
inDegree.put(project, inDegree.getOrDefault(project, 0) + 1);
}
}
// Topological sort
Queue<String> queue = new LinkedList<>();
for (String project : inDegree.keySet()) {
if (inDegree.get(project) == 0) queue.offer(project);
}
List<String> result = new ArrayList<>();
while (!queue.isEmpty()) {
String project = queue.poll();
result.add(project);
for (String next : graph.getOrDefault(project, new ArrayList<>())) {
inDegree.put(next, inDegree.get(next) - 1);
if (inDegree.get(next) == 0) queue.offer(next);
}
}
return result;
}

Time Complexity: O(V + E)


Practice L&T coding questions regularly!