Skip to content

ServiceNow Coding Questions - DSA Problems & Solutions

Practice ServiceNow placement paper coding questions with detailed solutions. Access ServiceNow OA coding problems in Java, Python.

This page contains ServiceNow coding questions from ServiceNow OA placement papers with detailed solutions.

ServiceNow OA Coding Section:

  • Problems: 2-3 coding problems
  • Time: 90 minutes
  • Languages: Java, Python
Q1: Design a system to automate workflow tasks with dependencies.

Solution (Java):

public List<String> executeWorkflow(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 task : dependencies.keySet()) {
inDegree.putIfAbsent(task, 0);
for (String dep : dependencies.get(task)) {
graph.putIfAbsent(dep, new ArrayList<>()).add(task);
inDegree.put(task, inDegree.getOrDefault(task, 0) + 1);
}
}
// Topological sort
Queue<String> queue = new LinkedList<>();
for (String task : inDegree.keySet()) {
if (inDegree.get(task) == 0) queue.offer(task);
}
List<String> result = new ArrayList<>();
while (!queue.isEmpty()) {
String task = queue.poll();
result.add(task);
for (String next : graph.getOrDefault(task, 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 ServiceNow coding questions regularly!