ServiceNow SWE Interview Question 2023 October | HashSets | on-campus

ServiceNow · Question · Posted Jun 2026

Question 1: Longest Consecutive Sequence Problem Statement Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. Constraints 0 <= nums.length <= 105 -109 <= nums[i] <= 109 Examples Example 1: Input: nums = [100,4,200,1,3,2] Output: 4 Explanation 1: The longest consecutive elements sequence is [1, 2, 3, 4]. Its length is 4. Sorting would take O(N log N) time, so we must use ...

The full answer & interview discussion are available to premium members.

Log in Create a free account