Google Onsite Round Coding Question For L4

Anonymous User
3218
May 26, 2025

Given an array find the sum of all subarrays which follow a +-1 difference AP
i.e the difference of the AP can be either 1 or -1
Individual elements are considered AP in itself
Input array : [7,2,3,4]
Answer : 7 + 2 + 3 + 4 + [2,3] + [2,3,4] + [3,4] = 37

I have no clue how to do it, can someone please help, like how is someone supposed to solve this in 35 minutes

Comments (32)