From 652717452d3442fc7244d252b9d13619a6fe4093 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 22 Oct 2025 03:52:12 -0600 Subject: [PATCH] adding algo --- .../top_150_questions_round_20/sqrtx.py | 20 +++++++++++++++++++ .../test_sqrtx_round_20.py | 0 2 files changed, 20 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_20/sqrtx.py create mode 100644 tests/test_150_questions_round_20/test_sqrtx_round_20.py diff --git a/src/my_project/interviews/top_150_questions_round_20/sqrtx.py b/src/my_project/interviews/top_150_questions_round_20/sqrtx.py new file mode 100644 index 00000000..b6b9c4f2 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_20/sqrtx.py @@ -0,0 +1,20 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def mySqrt(self, x: int) -> int: + + left, right = 0, x + + while left <= right: + + mid = (left + right)//2 + + if mid**2 < x: + left = mid + 1 + elif mid**2 > x: + right = mid - 1 + else: + return mid + + return min(left, right) \ No newline at end of file diff --git a/tests/test_150_questions_round_20/test_sqrtx_round_20.py b/tests/test_150_questions_round_20/test_sqrtx_round_20.py new file mode 100644 index 00000000..e69de29b