educative.io

Not working for the -ve number

Please let me know the solution for the negative numbers.

@rahul3 Solution # 1 is working fine for -ve numbers.

Then, there’s no possible O(1) solution when there are negative numbers in input? Why wouldn’t this be mentioned in the question?
Is it some kind of a sick joke to put Note at the end of the solution?

Hi @kalyan

My name is Shahrukh Naeem. I hope everything is going well with you. I will try my best to answer your query. Thank you for reaching out about this.

In Solution 2, we assumed that the given approach only works for non-negative numbers, it does not mean there’s no possible O(1) solution when there are negative numbers in input. We have provided a solution just for the implementation purpose with this assumption to make it simple and clear to understand. Secondly, If you have such kind of better solution for negative numbers you can also use it.

I hope that this guide is helpful. Remember that I am always available via message to help you with any difficulty you might encounter.

Regards,

Happy Learning :slight_smile:

1 Like