Negative Numbers

How to solve if the input array contains negative numbers?

hello @Jagrit there is no need to think if the number will be negative what we have to do.
compiler itself will consider negative number as different .

Okay but I meant how we can deal if negative number in bits. Suppose array is [-2,-2,-2,-4]. How to solve this?

@Jagrit negative number have their own binary representation .
suppose 2 and -2 have their different binary representation .
suppose they are represented by the 8bit number then in the negative MSB is always 1 and in the positive numbers the MSB is always 0.
please see the images below for better understanding.
binary-bin7 binary-bin8
i hope i have cleared your doubt .
Happy Learning !!

Thank you very much. Can you provide me with the code where negative cases are handled? and how we can check how many bits number it is?

@Jagrit here for your referance i am attaching the code https://ide.codingblocks.com/s/325372
please go through it and try to understand it.
please let me know if you dont understand anything inthis code .
i hope i have cleared your doubt .
Happy Learning !!

@Jagrit if your query is resolved now please mark this doubt as resolved .
On off the chance if you still have doubt you ca reopen the doubt as get your query resolved .
Happy Learning !!

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.