Google Onsite Round Coding Question For L4

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-05-26Added By Anonymous
Source: Link

Company: Google
Role: L4
Interview Stage: Onsite
Location: unknown
Year: unknown

Original Post Content:

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