Array Manipulation Hackerrank

Question link-https://www.hackerrank.com/challenges/crush/problem?isFullScreen=true

My function-

My code isn’t passing all the test cases.

Bro this question will be done with the help of segment tree. If you know the concept then apply it. Else it will result in TLE. cause of time complexity.

Okay, can you please resolve one dilemma for me??
It usually happens whenever I try to do any hard problem the solution will involve some tricky ds or algorithm. What should I do?? Solve only easy and medium??

What i do is when i fail to do hard question, i usually read the editorial or discussion section of that problem. From there i get few hints. Some geek gods mention it for us only that a particular DS will be needed to solve this question. So, go for hard problems but don’t spend to much time on only one question. Give it an hour for intuition part. If doesn’t get an idea. Try to find video tutorial or read editorial as per your convenience.

Accepted marking this doubt as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.