Skip to content

Commit 5578fbc

Browse files
Merge branch 'CodeHarborHub:main' into PradnyaGaitonde-patch-30
2 parents 1b7678b + 48b6c55 commit 5578fbc

File tree

13 files changed

+1815
-2
lines changed

13 files changed

+1815
-2
lines changed

docs/SQL/SQL-NOT-Operator.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
id: sql-not-operator
3+
title: Not Operator in SQL
4+
sidebar_label: Not Operator
5+
sidebar_position: 5
6+
tags: [sql, database, operator]
7+
description: In this tutorial, you will learn how to build queries with Negations to get the desired output.
8+
---
9+
10+
11+
In SQL, the NOT operator is used to negate a condition in a WHERE clause or other SQL statement. Its primary function is to reverse the logical meaning of the condition that follows it.
12+
13+
## Syntax
14+
```sql
15+
SELECT column1, column2, ...
16+
FROM table_name
17+
WHERE NOT condition;
18+
19+
```
20+
21+
## Advantages of SQL NOT Operator
22+
23+
**1.Exclusion of Unwanted Records:**
24+
- The NOT operator allows you to exclude records that match a certain condition. This is useful when you need to filter out specific data from your results.
25+
26+
**2.Simplification of Complex Conditions:**
27+
- It simplifies the writing of complex conditions by directly specifying what should not be included. Without the NOT operator, you might have to write more convoluted logic.
28+
29+
**3.Enhanced Readability and Maintainability:**
30+
- Using NOT can make the intention of the query clearer to someone reading the SQL code. Clearer code is easier to maintain and less prone to errors.
31+
32+
**4.Combination with Other Operators:**
33+
- The NOT operator can be combined with other operators such as IN, BETWEEN, and LIKE to provide more nuanced data filtering.
34+
35+
**5.Handling NULL Values:**
36+
- The NOT operator can also be used effectively with IS NULL or IS NOT NULL to filter out or include rows with NULL values.
37+
38+
**6.Flexibility in Subqueries:**
39+
- When used with subqueries, the NOT operator can help exclude sets of records efficiently.
40+
41+
**7.Versatility in Logical Expressions:**
42+
- It can be used to invert the result of any logical expression, providing versatility in query construction.
43+
44+
## Examples of Not Operator in SQL
45+
46+
### NOT LIKE
47+
```sql
48+
SELECT * FROM Customers
49+
WHERE CustomerName NOT LIKE 'A%';
50+
```
51+
52+
### NOT BETWEEN
53+
```sql
54+
SELECT * FROM Customers
55+
WHERE CustomerID NOT BETWEEN 10 AND 60;
56+
```
57+
58+
### NOT IN
59+
```sql
60+
SELECT * FROM Customers
61+
WHERE City NOT IN ('Paris', 'London');
62+
```
63+
64+
### NOT Greater Than
65+
```sql
66+
SELECT * FROM Customers
67+
WHERE NOT CustomerID > 50;
68+
```
69+
70+
### NOT Less Than
71+
```sql
72+
SELECT * FROM Customers
73+
WHERE NOT CustomerId < 50;
74+
```
75+
76+
77+
## Conclusion
78+
The NOT operator in SQL provides a straightforward way to negate conditions in SQL queries, allowing for more flexible and precise data retrieval. Understanding its usage is crucial for crafting effective SQL statements, particularly when dealing with complex filtering requirements.
79+
80+
---
81+
82+
## Authors:
83+
84+
<div style={{display: 'flex', flexWrap: 'wrap', justifyContent: 'space-between', gap: '10px'}}>
85+
{['damini-chachane'].map(username => (
86+
<Author key={username} username={username} />
87+
))}
88+
</div>

docusaurus.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ const config = {
343343
label: "Cookie Policy",
344344
to: "/cookie-policy",
345345
},
346+
347+
{
348+
label: "Licensing",
349+
to: "/License/",
350+
},
351+
346352
],
347353
},
348354
{

dsa-problems/leetcode-problems/0900-0999.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ export const problems = [
117117
problemName: "917. Reverse Only Letters",
118118
difficulty: "Easy",
119119
leetCodeLink: "https://leetcode.com/problems/reverse-only-letters",
120-
solutionLink: "#"
120+
solutionLink: "/dsa-solutions/lc-solutions/0900-0999/reverse-only-letters"
121121
},
122122
{
123123
problemName: "918. Maximum Sum Circular Subarray",
124124
difficulty: "Medium",
125125
leetCodeLink: "https://leetcode.com/problems/maximum-sum-circular-subarray",
126-
solutionLink: "#"
126+
solutionLink: "/dsa-solutions/lc-solutions/0900-0999/maximum-sum-circular-subarray"
127127
},
128128
{
129129
problemName: "919. Complete Binary Tree Inserter",

dsa-problems/leetcode-problems/3100-3199.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ export const problems = [
448448
"leetCodeLink": "https://leetcode.com/problems/maximum-total-reward-using-operations-ii",
449449
"solutionLink": "#"
450450
},
451+
{
452+
"problemName": "3183. The Number of Ways To Make The Sum",
453+
"difficulty": "Medium",
454+
"leetCodeLink": "https://leetcode.com/problems/the-number-of-ways-to-make-the-sum",
455+
"solutionLink": "#"
456+
},
451457
];
452458

453459
<Table
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
id: word-search
3+
title: Word Search(LeetCode)
4+
sidebar_label: 0079-Word Search
5+
tags:
6+
- Array
7+
- String
8+
- Backtracking
9+
- Matrix
10+
description: Given an m x n grid of characters board and a string word, return true if word exists in the grid.
11+
---
12+
13+
## Problem Statement
14+
15+
Given an `m x n` grid of characters `board` and a string `word`, return `true` if `word` exists in the grid.
16+
17+
The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.
18+
19+
### Examples
20+
21+
**Example 1:**
22+
23+
![image](https://github.com/PradnyaGaitonde/codeharborhub.github.io/assets/116059908/dc23f6be-e216-4ad1-89bc-178cf3039262)
24+
25+
```plaintext
26+
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"
27+
Output: true
28+
```
29+
30+
**Example 2:**
31+
32+
![image](https://github.com/PradnyaGaitonde/codeharborhub.github.io/assets/116059908/c3905a94-2a40-4dee-a4bf-42b77ba2b91a)
33+
34+
```plaintext
35+
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE"
36+
Output: true
37+
```
38+
39+
**Example 3:**
40+
41+
![image](https://github.com/PradnyaGaitonde/codeharborhub.github.io/assets/116059908/c56f9ea3-8247-484b-943a-0c38ea32465c)
42+
43+
```plaintext
44+
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB"
45+
Output: false
46+
```
47+
48+
### Constraints
49+
50+
- `m == board.length`
51+
- `n = board[i].length`
52+
- `1 <= m, n <= 6`
53+
- `1 <= word.length <= 15`
54+
- `board` and `word` consists of only lowercase and uppercase English letters.
55+
56+
## Solution
57+
58+
### Approach
59+
60+
#### Algorithm
61+
62+
1. Initialization:
63+
* Convert the input word to a character array `w`.
64+
* Iterate through each cell in the board using nested loops.
65+
2. Recursive Search:
66+
* For each cell in the board, call the recursive function `exist`.
67+
* The recursive function `exist` takes parameters: the board, current cell coordinates `(y, x)`, the word array, and the current index `i` in the word array.
68+
* Base cases:
69+
* If `i` equals the length of the word, return `true` (all characters are matched).
70+
* If the current cell `(y, x)` is out of bounds or does not match the current character in the word array, return `false`.
71+
* Mark the current cell as visited by toggling the 8th bit using `board[y][x] ^= 256`.
72+
* Recursively check all four possible directions (right, left, down, up) from the current cell.
73+
* After the recursive calls, unmark the current cell by toggling the 8th bit again using `board[y][x] ^= 256`.
74+
* Return `true` if any of the recursive calls return `true`, indicating that the word exists in the board starting from the current cell.
75+
3. Return Result:
76+
* Return `true` if the word is found starting from any cell, otherwise return `false`.
77+
78+
#### Implementation
79+
80+
```Java
81+
public boolean exist(char[][] board, String word) {
82+
char[] w = word.toCharArray();
83+
for (int y=0; y<board.length; y++) {
84+
for (int x=0; x<board[y].length; x++) {
85+
if (exist(board, y, x, w, 0)) return true;
86+
}
87+
}
88+
return false;
89+
}
90+
91+
private boolean exist(char[][] board, int y, int x, char[] word, int i) {
92+
if (i == word.length) return true;
93+
if (y<0 || x<0 || y == board.length || x == board[y].length) return false;
94+
if (board[y][x] != word[i]) return false;
95+
board[y][x] ^= 256;
96+
boolean exist = exist(board, y, x+1, word, i+1)
97+
|| exist(board, y, x-1, word, i+1)
98+
|| exist(board, y+1, x, word, i+1)
99+
|| exist(board, y-1, x, word, i+1);
100+
board[y][x] ^= 256;
101+
return exist;
102+
}
103+
```
104+
105+
### Complexity Analysis
106+
107+
- **Time complexity**: $O(N.3^L)$
108+
* N is the number of cells in the board (i.e., board.length * board[0].length).
109+
* L is the length of the word.
110+
* Each cell can be a starting point, and from each cell, we explore up to 3 directions (since we cannot revisit the previous cell, reducing from 4 to 3).
111+
112+
- **Space complexity**: O(L)
113+
* The recursion stack can go up to a depth of L, which is the length of the word.
114+
* No additional data structures are used that grow with input size (in-place modification of the board is used).
115+
116+
### Conclusion
117+
118+
This recursive solution effectively finds the word in the board by exploring all possible paths and backtracking when a path does not lead to the solution. By marking cells with a bitmask, it avoids using additional memory for visited states, making the algorithm space-efficient. The time complexity reflects the worst-case scenario of exploring all possible paths, while the space complexity is primarily driven by the depth of the recursion stack. This approach is both time and space-efficient, making it suitable for large boards and words.

0 commit comments

Comments
 (0)