Skip to main content

ServiceNow Coding Interview Questions

26 ServiceNow coding interview problems with full optimal solutions — 15 easy, 8 medium, 3 hard. Every problem ships with multiple approaches (brute-force first, then the optimal), complexity tables for each, company-specific tips on what an ServiceNow interviewer values, and a FAQ section.

  • #1easyfrequently asked

    1. Two Sum

    Given an array of integers and a target, return indices of the two numbers that add up to target. ServiceNow asks this to confirm you reach for a hash map for O(n) lookups — the same pattern they use in ticket de-duplication and SLA pair-matching.

  • #2easyfrequently asked

    2. Valid Parentheses

    Given a string of brackets, decide if every opener has a matching closer in the correct order. ServiceNow asks this to confirm you reach for a stack — the same data structure their workflow engine uses to nest sub-flows and rollback approval steps.

  • #3easyfrequently asked

    3. Merge Two Sorted Lists

    Splice two sorted linked lists into one sorted list. ServiceNow asks this to test whether you handle dummy-head + tail-pointer mechanics cleanly — the same shape they use when merging two prioritized ticket queues.

  • #4easysometimes asked

    4. Remove Duplicates from Sorted Array

    Strip duplicates from a sorted array in place, returning the new length. ServiceNow uses this to test the slow/fast two-pointer pattern they apply when collapsing repeated ticket events into a single change record.

  • #5easysometimes asked

    5. Remove Element

    Remove every occurrence of a target value from an array in place, returning the new length. ServiceNow uses this to confirm you understand in-place compaction — the same trick they use when purging soft-deleted incident rows from a result buffer.

  • #6easyfrequently asked

    6. Search Insert Position

    Find the index where a target should be inserted in a sorted array to keep it sorted. ServiceNow uses this to verify binary-search fluency — the same primitive their SLA timer scheduler uses to insert new deadlines into an ordered heap.

  • #7easysometimes asked

    7. Plus One

    Given a digit array representing a non-negative integer, return the array after adding one. ServiceNow uses this to test carry-propagation hygiene — the same shape they apply when incrementing record version counters in their CMDB.

  • #8easysometimes asked

    8. Merge Sorted Array

    Merge nums2 into nums1 (which has trailing zero slots) so that nums1 stays sorted, in place. ServiceNow uses this to test the back-to-front three-pointer trick — the same shape they apply when blending two priority queues without an auxiliary buffer.

  • #9easysometimes asked

    9. Binary Tree Inorder Traversal

    Return the inorder traversal of a binary tree's node values. ServiceNow asks this to confirm recursion fluency and to see if you can write the iterative stack-based version — the same trick they use when walking approval-chain trees in their workflow engine.

  • #10easysometimes asked

    10. Same Tree

    Given two binary trees, decide whether they are structurally identical and have equal values. ServiceNow asks this to verify recursive tree equality fluency — the same shape they apply when diffing two snapshots of a workflow definition.

  • #11easysometimes asked

    11. Symmetric Tree

    Given the root of a binary tree, check whether it is a mirror of itself. ServiceNow asks this to confirm you can write a paired recursion (compare left.left with right.right, left.right with right.left) — useful in any mirrored workflow validation.

  • #12easyfrequently asked

    12. Maximum Depth of Binary Tree

    Find the maximum depth of a binary tree by counting the longest root-to-leaf path. ServiceNow uses this to probe tree-recursion fundamentals, reflecting their heavy use of hierarchical data models in CMDB and approval-chain trees.

  • #13easysometimes asked

    13. Path Sum

    Determine if a binary tree has a root-to-leaf path whose node values sum to a target. ServiceNow favors this to test recursive tree traversal under a constraint, which mirrors how their workflow engine evaluates cumulative cost thresholds in approval chains.

  • #14easysometimes asked

    14. Pascal's Triangle

    Generate the first numRows of Pascal's triangle. ServiceNow uses this to verify candidates can build and index 2-D arrays correctly — a skill directly relevant to their report-grid and matrix-based workflow analytics features.

  • #15easysometimes asked

    15. Single Number

    Find the one element in an array that appears exactly once when all others appear twice. ServiceNow uses this to test bit-manipulation awareness and O(1)-space thinking — skills that surface when candidates discuss efficient event-deduplication in high-volume incident streams.

  • #16mediumfrequently asked

    16. Longest Substring Without Repeating Characters

    Find the length of the longest substring with all unique characters using a sliding window. ServiceNow asks this to assess hash-map + two-pointer fluency — the same pattern underpins their duplicate-detection logic in event correlation pipelines.

  • #17mediumfrequently asked

    17. Number of Islands

    Count connected components of '1's in a 2-D grid using DFS or BFS. ServiceNow asks this to test graph traversal reasoning — the same connected-component logic powers their CMDB relationship discovery, where service clusters must be identified from a dependency grid.

  • #18mediumfrequently asked

    18. Course Schedule

    Determine if you can finish all courses given prerequisite dependencies — a cycle-detection problem on a directed graph. ServiceNow asks this because workflow dependency graphs in their automation engine must be acyclic; detecting cycles is a core interview signal.

  • #19mediumsometimes asked

    19. Clone Graph

    Deep-copy a connected undirected graph where each node has a value and a list of neighbors. ServiceNow asks this because CMDB cloning — duplicating a service map with all its CI relationships intact — is a real product operation, and the hash-map-keyed-by-original-node pattern is directly applicable.

  • #20mediumfrequently asked

    20. Implement Trie (Prefix Tree)

    Build a trie data structure supporting insert, search, and prefix-search operations. ServiceNow uses this to assess data-structure design skills — trie-based prefix search is the backbone of their universal search autocomplete that spans incidents, assets, and knowledge articles.

  • #21mediumfrequently asked

    21. Binary Tree Level Order Traversal

    Return all node values of a binary tree grouped by level, using BFS. ServiceNow asks this because hierarchical BFS represents approval tiers in their workflow engine — each level is a stage gate — and the level-grouping technique surfaces directly in their reporting dashboards.

  • #22mediumfrequently asked

    22. LRU Cache

    Design a data structure that supports O(1) get and put with least-recently-used eviction. ServiceNow asks this because their platform caches CMDB records and knowledge article lookups at high QPS, making LRU cache design directly applicable to real engineering work.

  • #23mediumsometimes asked

    23. Word Break

    Determine if a string can be segmented into words from a dictionary using dynamic programming. ServiceNow uses this to test DP problem decomposition — the same bottom-up memoization pattern powers their rule-engine tokenization for workflow trigger parsing.

  • #24hardrarely asked

    24. Median of Two Sorted Arrays

    Find the median of two sorted arrays in O(log(m+n)) time using binary search on partition points. ServiceNow asks this hard problem for senior roles because the binary-search-on-partition insight mirrors the data-partitioning reasoning required when merging sorted incident streams across multiple database shards.

  • #25hardsometimes asked

    25. Trapping Rain Water

    Calculate the total water trapped between elevation bars after rain using two-pointer or stack approaches. ServiceNow asks this hard classic to test multi-pointer reasoning under constraints — the capacity-calculation pattern maps to buffer-management logic in their event ingestion queues.

  • #26hardrarely asked

    26. Serialize and Deserialize Binary Tree

    Design algorithms to convert a binary tree to a string and back without information loss. ServiceNow asks this hard problem because serializing and restoring hierarchical data structures is core to their workflow-snapshot and CMDB-export features — interviewers grade candidates on null-marker strategy and delimiter robustness.

ServiceNow Coding Interview Questions — Full Solutions — InterviewChamp.AI