## Service Now Interview Question for Staff Engineers

Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
0
of 0 vote

A straightforward application of Kadane's algorithm. Sharing my solution in Python below:

``````def maximumSubarray(nums):
localMax = globalMax = nums[0]
for ind, num in enumerate(nums[1:]):
localMax = max(num, num + localMax)
globalMax = max(localMax, globalMax)

return globalMax``````

Test code

``````nums = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
print('Maximum sum subarray ->' ,maximumSubarray(nums))
# OUTPUT: Maximum sum subarray -> 6``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

Linear Time approach :

``````def maxSubArray(nums):
curr_sum = nums[0]
max_sum = nums[0]

for i in range(1,len(nums)):
curr_sum += nums[i]
if curr_sum < nums[i]:
curr_sum = nums[i]
max_sum = max(max_sum, curr_sum)

return max_sum``````

http://worldkosh.com/blog/2018/09/13/largest-sum-subarray/

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public class ArrayBiggestSum {

public static void main(String[] args) {
int biggestSum = 0;
int[] intArr = { 1, 3, 5, 7, 7, 8, 8, 9, -2, 14, -5, 0, 4 };
for (int i = 0; i < intArr.length; i++) {
for (int j = i + 1; j < intArr.length; j++) {
if (intArr[i] + intArr[j] > biggestSum) {
biggestSum = intArr[i] + intArr[j];
}
}
}
System.out.println(biggestSum);
}
}``````

Output -
23

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.