You have given two 32 bit signed integers, and you have to check if their multiplication will overflow 32 bit signed integer or not.
An integer overflow occurs when you attempt to store inside an integer variable a value that is larger than the maximum value the variable can hold.
The first line of input contains the first 32 bit signed integer 'A'.
The second line of input contains the second 32 bit signed integer 'B'.
Output format :
The only line of output contains 'true' if the multiplication of 'A' and 'B' is overflowing in 32 bit signed integer or 'false' otherwise.
Note:
Return the expected boolean value from the function, no need to print anything.
-2^31 <= A <= 2^31 - 1
-2^31 <= B <= 2^31 - 1
where 'A' and 'B' are the given integers.
Time Limit: 0.5 sec.
Note :
Try to solve this problem assuming you can only have 32 bit signed integers (Without using any typecasting to other datatypes)
127842721
9
false
The product of the given two numbers is 1150584489, which is less than 2^31. Hence the output is false.
-1799120
-2323232
true
-78921277
1927279
true
Think of the possibilities where the operation may result in an overflow.
O(1).
Since multiplying two numbers takes constant time.
O(1).
Constant space is used.