Check Integer Overflow

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.

Input format :
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.
Constraints :
-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)
CodingNinjas
author
2y
Typecasting
  1. Typecast either of the operands to a type that can hold a really large number(exceeding the limits of integer).
  2. Take a product of the operands now
  3. Check the result of the operation:
    1. If it is n...read more
CodingNinjas
author
2y
Positive And Negative Case

Let’s say the two integers being multiplied together are ‘a’ and ‘b’.

There will be three possibilities:

  • a = 0: If a is zero, then a*b will be 0 and thus there will be no over...read more
Help your peers!
Add answer anonymously...
Thoughts2Binary Consulting & Solutions Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter