diff --git a/courses/html/_category_.json b/courses/html/_category_.json index 0daa5a64e..3d1e28d90 100644 --- a/courses/html/_category_.json +++ b/courses/html/_category_.json @@ -1,8 +1,8 @@ { - "label": "HTML", - "position": 3, - "link": { - "type": "generated-index", - "description": "Getting started with HTML, the language that powers the web." - } - } \ No newline at end of file + "label": "HTML", + "position": 3, + "link": { + "type": "generated-index", + "description": "Getting started with HTML, the language that powers the web." + } +} diff --git a/courses/html/basic/_category_.json b/courses/html/basic/_category_.json index 10abdbe07..5627ea81c 100644 --- a/courses/html/basic/_category_.json +++ b/courses/html/basic/_category_.json @@ -1,8 +1,8 @@ { - "label": "HTML Basics", - "position": 2, - "link": { - "type": "generated-index", - "description": "Learn the basics of HTML, the language that powers the web." - } - } \ No newline at end of file + "label": "HTML Basics", + "position": 2, + "link": { + "type": "generated-index", + "description": "Learn the basics of HTML, the language that powers the web." + } +} diff --git a/courses/html/basic/intro-html.md b/courses/html/basic/intro-html.md index 12904252b..66915f85d 100644 --- a/courses/html/basic/intro-html.md +++ b/courses/html/basic/intro-html.md @@ -31,9 +31,8 @@ To create your first web page, you need to create an HTML file. An HTML file is Here is an example of a simple HTML file: - ```html title="index.html" - + My First Web Page @@ -50,7 +49,6 @@ Here is an example of a simple HTML file:

Welcome to my first web page.

- In this example, the HTML file contains the following elements: - ``: This declaration defines the document type and version of HTML. @@ -82,4 +80,4 @@ HTML is the foundation of web development. Learning HTML is essential for anyone ## Summary -In this section, you learned the basics of HTML, the foundation of web development. You created your first web page using HTML and learned about HTML elements and attributes. HTML is the standard markup language for creating web pages, and it is essential for anyone who wants to create web pages and web applications. In the next section, you will learn more about HTML elements and attributes. \ No newline at end of file +In this section, you learned the basics of HTML, the foundation of web development. You created your first web page using HTML and learned about HTML elements and attributes. HTML is the standard markup language for creating web pages, and it is essential for anyone who wants to create web pages and web applications. In the next section, you will learn more about HTML elements and attributes. diff --git a/dsa-solutions/gfg-solutions/Easy problems/square-root.md b/dsa-solutions/gfg-solutions/Easy problems/square-root.md index f0c2eb177..c249e2811 100644 --- a/dsa-solutions/gfg-solutions/Easy problems/square-root.md +++ b/dsa-solutions/gfg-solutions/Easy problems/square-root.md @@ -1,193 +1,193 @@ ---- -id: square-root -title: Square Root -sidebar_label: Square-Root -tags: - - Math - - Binary Search -description: "This document provides solutions to the problem of finding the Square Root of an integer." ---- - -## Problem - -Given an integer `x`, find the square root of `x`. If `x` is not a perfect square, then return the floor value of √x. - -### Examples - -**Example 1:** - -``` -Input: x = 5 -Output: 2 -Explanation: Since 5 is not a perfect square, the floor of the square root of 5 is 2. -``` - -**Example 2:** - -``` -Input: x = 4 -Output: 2 -Explanation: Since 4 is a perfect square, its square root is 2. -``` - -### Your Task - -You don't need to read input or print anything. The task is to complete the function `floorSqrt()` which takes `x` as the input parameter and returns its square root. Note: Try solving the question without using the sqrt function. The value of `x` ≥ 0. - -**Expected Time Complexity:** $O(log N)$ -**Expected Auxiliary Space:** $O(1)$ - -**Constraints** - -- `1 ≤ x ≤ 10^7` - -## Solution - -### Intuition & Approach - -To find the square root of a number without using the built-in `sqrt` function, we can use binary search. This approach leverages the fact that the square root of `x` must lie between `0` and `x`. By repeatedly narrowing down the range using binary search, we can efficiently find the floor value of the square root. - -### Implementation - - - - -```python -class Solution: - def floorSqrt(self, x: int) -> int: - if x == 0 or x == 1: - return x - start, end = 1, x - ans = 0 - while start <= end: - mid = (start + end) // 2 - if mid * mid == x: - return mid - if mid * mid < x: - start = mid + 1 - ans = mid - else: - end = mid - 1 - return ans -``` - - - - -```java -class Solution { - long floorSqrt(long x) { - if (x == 0 || x == 1) { - return x; - } - long start = 1, end = x, ans = 0; - while (start <= end) { - long mid = (start + end) / 2; - if (mid * mid == x) { - return mid; - } - if (mid * mid < x) { - start = mid + 1; - ans = mid; - } else { - end = mid - 1; - } - } - return ans; - } -} -``` - - - - -```cpp -class Solution { -public: - long long int floorSqrt(long long int x) { - if (x == 0 || x == 1) - return x; - long long int start = 1, end = x, ans = 0; - while (start <= end) { - long long int mid = (start + end) / 2; - if (mid * mid == x) - return mid; - if (mid * mid < x) { - start = mid + 1; - ans = mid; - } else { - end = mid - 1; - } - } - return ans; - } -}; -``` - - - - -```javascript -class Solution { - floorSqrt(x) { - if (x === 0 || x === 1) { - return x; - } - let start = 1, - end = x, - ans = 0; - while (start <= end) { - let mid = Math.floor((start + end) / 2); - if (mid * mid === x) { - return mid; - } - if (mid * mid < x) { - start = mid + 1; - ans = mid; - } else { - end = mid - 1; - } - } - return ans; - } -} -``` - - - - -```typescript -class Solution { - floorSqrt(x: number): number { - if (x === 0 || x === 1) { - return x; - } - let start = 1, - end = x, - ans = 0; - while (start <= end) { - let mid = Math.floor((start + end) / 2); - if (mid * mid === x) { - return mid; - } - if (mid * mid < x) { - start = mid + 1; - ans = mid; - } else { - end = mid - 1; - } - } - return ans; - } -} -``` - - - - -## Complexity Analysis - -The provided solutions efficiently find the floor value of the square root of a given integer `x` using binary search. This approach ensures a time complexity of $ O(log N) and an auxiliary space complexity of $O(1)$. The algorithms are designed to handle large values of `x` up to 10^7 efficiently without relying on built-in square root functions. - -**Time Complexity:** $O(log N)$ -**Auxiliary Space:** $O(1)$ +--- +id: square-root +title: Square Root +sidebar_label: Square-Root +tags: + - Math + - Binary Search +description: "This document provides solutions to the problem of finding the Square Root of an integer." +--- + +## Problem + +Given an integer `x`, find the square root of `x`. If `x` is not a perfect square, then return the floor value of √x. + +### Examples + +**Example 1:** + +``` +Input: x = 5 +Output: 2 +Explanation: Since 5 is not a perfect square, the floor of the square root of 5 is 2. +``` + +**Example 2:** + +``` +Input: x = 4 +Output: 2 +Explanation: Since 4 is a perfect square, its square root is 2. +``` + +### Your Task + +You don't need to read input or print anything. The task is to complete the function `floorSqrt()` which takes `x` as the input parameter and returns its square root. Note: Try solving the question without using the sqrt function. The value of `x` ≥ 0. + +**Expected Time Complexity:** $O(log N)$ +**Expected Auxiliary Space:** $O(1)$ + +**Constraints** + +- `1 ≤ x ≤ 10^7` + +## Solution + +### Intuition & Approach + +To find the square root of a number without using the built-in `sqrt` function, we can use binary search. This approach leverages the fact that the square root of `x` must lie between `0` and `x`. By repeatedly narrowing down the range using binary search, we can efficiently find the floor value of the square root. + +### Implementation + + + + +```python +class Solution: + def floorSqrt(self, x: int) -> int: + if x == 0 or x == 1: + return x + start, end = 1, x + ans = 0 + while start <= end: + mid = (start + end) // 2 + if mid * mid == x: + return mid + if mid * mid < x: + start = mid + 1 + ans = mid + else: + end = mid - 1 + return ans +``` + + + + +```java +class Solution { + long floorSqrt(long x) { + if (x == 0 || x == 1) { + return x; + } + long start = 1, end = x, ans = 0; + while (start <= end) { + long mid = (start + end) / 2; + if (mid * mid == x) { + return mid; + } + if (mid * mid < x) { + start = mid + 1; + ans = mid; + } else { + end = mid - 1; + } + } + return ans; + } +} +``` + + + + +```cpp +class Solution { +public: + long long int floorSqrt(long long int x) { + if (x == 0 || x == 1) + return x; + long long int start = 1, end = x, ans = 0; + while (start <= end) { + long long int mid = (start + end) / 2; + if (mid * mid == x) + return mid; + if (mid * mid < x) { + start = mid + 1; + ans = mid; + } else { + end = mid - 1; + } + } + return ans; + } +}; +``` + + + + +```javascript +class Solution { + floorSqrt(x) { + if (x === 0 || x === 1) { + return x; + } + let start = 1, + end = x, + ans = 0; + while (start <= end) { + let mid = Math.floor((start + end) / 2); + if (mid * mid === x) { + return mid; + } + if (mid * mid < x) { + start = mid + 1; + ans = mid; + } else { + end = mid - 1; + } + } + return ans; + } +} +``` + + + + +```typescript +class Solution { + floorSqrt(x: number): number { + if (x === 0 || x === 1) { + return x; + } + let start = 1, + end = x, + ans = 0; + while (start <= end) { + let mid = Math.floor((start + end) / 2); + if (mid * mid === x) { + return mid; + } + if (mid * mid < x) { + start = mid + 1; + ans = mid; + } else { + end = mid - 1; + } + } + return ans; + } +} +``` + + + + +## Complexity Analysis + +The provided solutions efficiently find the floor value of the square root of a given integer `x` using binary search. This approach ensures a time complexity of $ O(log N) and an auxiliary space complexity of $O(1)$. The algorithms are designed to handle large values of `x` up to 10^7 efficiently without relying on built-in square root functions. + +**Time Complexity:** $O(log N)$ +**Auxiliary Space:** $O(1)$