Array Manipulation Problem

Getting half test cases failed please help

can you please tell me what is wrong with my code

okay give meh 10 min

but please tell me what code i need to past in the hackerrank editor
or i paste the entire code u shared ??

entire code you can paste

@ashwani225


since the queries are 1 indexed based so take array to be n+1 size

but even then


u score 24
since constraints are large
and the time complexity is high
that is why It is HARD question u need to reduce the complexity of the program

u can watch out my code for the optimised method/algo

1 Like


test case where it fails
u are nearly using O(NMN) complexity

1 Like

Okay thanks got it :smiley:

1 Like

one thing please tell me every time I apply brute force but I didn’t got logic for optimised code.
How can I get logic of optimised code

1 Like

see this can only be achieved with a lot of practice

first of all go through all standard questions ( ones disccussed in the course)
there the most optimised methods are discussed
search those question on gfg
start reading from brute approach
then the gfg articles moves to more optimised approach
so u`ll thought process will change
gradually

then start practising leetcode
read the discussion panel there are pro programming write the solutions for u even if u do the question by your self give a moments time to read their solution … learning will help u to move to more optimised solutions

2 Likes