problem from LocJun2017 problem code HHMGN

/help me to identify my error (giving wrong ans)/

pls allign the code properly, its quite tough to understand. best will be if you can give a link of your submission

moreover , regarding the question .

  1. first sort the array.
  2. store presums in array
  3. start rolling over from 1-arr[n-1].
  4. use the presums + the number*(no greater then them) to check.

regarding your solution , i find you are doing it in O(n*n).do it in O(nlogn).
here is a link to my code.
do upvote if u understand , else ask .

But didnt the Q state that-

to find a number K **from array A** such that if all elements in A 
1 Like

oh gosssh , i missed it but i guess the weak test cases made it a right answer :slight_smile:

hey here is my accepted solution and i hope my code is easy to understand

please ask if you have any doubt.

Thanks, Yeah i understood question in a different Way