Google | Phone Screen | L4

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2025-03-14Added By Anonymous
Source: Link
🧭 Experience: unknown ✅ Outcome: unknown 💰 Compensation: unknown 📍 Location: unknown 🏢 Company: Google 🎓 Education: unknown 🎁 Benefits: unknown 📅 Offer Date: unknown An array with values is given. After removing an element, find whether the array can be divided into two parts, where the sum has to be equal and elements has to be continuous. Eg: [3, 1, 1, 1, 7] -> removing 7 -> True. (3) & (1, 1, 1) [1, 3, 1, 1, 7] -> removing 7 -> False, since the array can't be divided into two parts. Follow-up: if the array is circular. Eg: [1, 3, 1, 1, 7] -> removing 7 -> True, (1, 1, 1) & (3) I provided O(N * N) time and O(N) space for both, coded original, explained follow-up. My code for main question: ``` def divide(arr): def canDivide(arr1): total = sum(arr1) half = total // 2 curSum = 0 for n in arr1: curSum += n if curSum == half: return True elif curSum > half: break return False for i in range(len(arr)): arr1 = arr[:] arr1.remove(arr1[i]) if canDivide(arr1): return True return False ``` #google
Comments