Computing with floating-point math can give wrong answers. sqrt(49) might return instead of . If you cast that to an integer, you get .
For integer square root, use binary search instead. Search for the largest where . This avoids floating-point errors and runs in time, space.
Newton's method is another option: start with guess , then set using integer division. It converges fast, usually under iterations even for -bit inputs.
When a problem asks "is a perfect square?" or "find the integer square root," avoid math.sqrt. Use binary search or Newton's method with integer arithmetic.