- Given An Array Of Positive Integers Arr Remove The Smallest Subarray Possibly Empty Such That The Sum Of The Remainin 1 (65.62 KiB) Viewed 37 times
Given an array of positive integers arr, remove the smallest subarray (possibly empty) such that the sum of the remainin
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Given an array of positive integers arr, remove the smallest subarray (possibly empty) such that the sum of the remainin
Given an array of positive integers arr, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by d. It is not allowed to remove the whole array. Return the smallest subarray that you need to remove, or −1) if it's impossible. A subarray is defined as a contiguous block of elements in the array. Make sure your program can take inputs from the terminal. Sample Input1: arr=[3,1,4,2],d=6 Sample Output1: [4] Sample Input2: arr=[6,3,5,2],d=9 Sample Output2: [5,2] Sample Input3: arr=[1,2,3],d=3 Sample Output3: 0 comment: empty case Sample Input4: arr=[1,2,3],d=7 Sample Output4: −1 comment: impossible case Hint: Suppose you know the remainder for the sum of the entire array.