Any optimized code?

iam getting solution with only o(n^2) only can anyone give o(n)solution for that with clear description

Link to original problem, please? People don’t want to have to squint and read a photograph of a screen :slight_smile:

O(n) use hashing

1 Like

i also seen this but for array problems is necessary to use hash compulsory for getting optimal solution or anyother alternative for this ??

It depends on problem to problem there are many algorithms (segment tree hasing dp greedy ) which need to be applied according to given problem .

it is known to us by practice am i correct???so i implement it by hashing… can anyother alternative?

Yup it’s comes from practice and it is standard 2 sum problem. I don’t know any better method than o(n) hashing.

O(n) hashing best way to begin with