My issue
I am getting time limit exceeded for my code but i have got correct output, help me to solve the problem.
My code
# cook your dish here
# Function to perform integer division
def divide_integer(A, B):
INT_MAX = 2**31 - 1
INT_MIN = -2**31
# Handle division by zero
if B == 0:
return INT_MAX if A > 0 else INT_MIN
# Handle overflow cases
if A == INT_MIN and B == -1:
return INT_MAX
# Determine the sign of the result
sign = -1 if (A < 0) ^ (B < 0) else 1
# Take the absolute values for division
A, B = abs(A), abs(B)
quotient = 0
while A >= B:
A -= B
quotient += 1
return sign * quotient
# Number of test cases
T = int(input().strip())
for _ in range(T):
# Input for each test case
A, B = map(int, input().split())
# Perform integer division and print the result
result = divide_integer(A, B)
print(result)
Learning course: Python with Data structures
Problem Link: Bit Manipulation - Divide Integers Practice Problem in Python with Data structures - CodeChef