From 27f2f6f6a04b0fe15f5d655ecc14d1f06f7a16a3 Mon Sep 17 00:00:00 2001
From: Sadaf <137484958+SadafKausar2025@users.noreply.github.com>
Date: Mon, 10 Jun 2024 15:33:23 +0530
Subject: [PATCH 1/2] Added String topic in DSA
---
docs/dsa/strings/_category_.json | 8 +
.../leetcode_practice_problems_strings.md | 31 ++++
docs/dsa/strings/strings-dsa.md | 140 ++++++++++++++++++
...7-Letter-Combinations-of-a-Phone-Number.md | 7 +-
4 files changed, 183 insertions(+), 3 deletions(-)
create mode 100644 docs/dsa/strings/_category_.json
create mode 100644 docs/dsa/strings/leetcode_practice_problems_strings.md
create mode 100644 docs/dsa/strings/strings-dsa.md
diff --git a/docs/dsa/strings/_category_.json b/docs/dsa/strings/_category_.json
new file mode 100644
index 000000000..5e94df7ac
--- /dev/null
+++ b/docs/dsa/strings/_category_.json
@@ -0,0 +1,8 @@
+{
+ "label": "String",
+ "position": 8,
+ "link": {
+ "type": "generated-index",
+ "description": "In data structures, a string is a sequence of characters used to represent text. Strings are commonly used for storing and manipulating textual data in computer programs. They can be manipulated using various operations like concatenation, substring extraction, and comparison."
+ }
+}
diff --git a/docs/dsa/strings/leetcode_practice_problems_strings.md b/docs/dsa/strings/leetcode_practice_problems_strings.md
new file mode 100644
index 000000000..a9ea2bd93
--- /dev/null
+++ b/docs/dsa/strings/leetcode_practice_problems_strings.md
@@ -0,0 +1,31 @@
+# Practice Problems for Strings
+
+To further practice and test your understanding of strings, consider solving the following problems from LeetCode:
+
+## Easy
+
+1. [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/)
+2. [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/)
+3. [Implement strStr()](https://leetcode.com/problems/implement-strstr/)
+4. [Count and Say](https://leetcode.com/problems/count-and-say/)
+5. [Reverse String](https://leetcode.com/problems/reverse-string/)
+6. [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/)
+7. [Valid Anagram](https://leetcode.com/problems/valid-anagram/)
+8. [Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string/)
+9. [Detect Capital](https://leetcode.com/problems/detect-capital/)
+10. [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern/)
+
+## Medium
+
+11. [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)
+12. [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/)
+13. [Group Anagrams](https://leetcode.com/problems/group-anagrams/)
+14. [Decode String](https://leetcode.com/problems/decode-string/)
+15. [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/)
+16. [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)
+17. [Simplify Path](https://leetcode.com/problems/simplify-path/)
+18. [Add Bold Tag in String](https://leetcode.com/problems/add-bold-tag-in-string/)
+19. [Find All Anagrams in a String](https://leetcode.com/problems/find-all-anagrams-in-a-string/)
+20. [Longest Palindromic Subsequence](https://leetcode.com/problems/longest-palindromic-subsequence/)
+
+Engaging with these problems will help reinforce the concepts learned and provide practical experience in using strings effectively. By practicing these problems, you will enhance your problem-solving skills and deepen your understanding of string manipulation in various contexts.
diff --git a/docs/dsa/strings/strings-dsa.md b/docs/dsa/strings/strings-dsa.md
new file mode 100644
index 000000000..cc0d595af
--- /dev/null
+++ b/docs/dsa/strings/strings-dsa.md
@@ -0,0 +1,140 @@
+---
+id: strings-in-dsa
+title: Strings in Data Structures and Algorithms
+sidebar_label: Strings
+sidebar_position: 1
+description: "A string is a sequence of characters. It is a data structure that represents a sequence of characters, either as a literal constant or as some kind of variable. In data structures and algorithms, strings are used in a wide range of applications such as text processing, pattern matching, and data serialization."
+tags:
+ [
+ dsa,
+ data-structures,
+ strings,
+ string,
+ string-data-structure,
+ string-in-dsa,
+ string-in-data-structure,
+ string-in-algorithm,
+ string-in-dsa-example,
+ string-in-dsa-explanation,
+ string-in-dsa-conclusion,
+ string-in-dsa-importance,
+ string-in-dsa-syntax,
+ string-in-dsa-declaration,
+ string-in-dsa-access,
+ string-in-dsa-update,
+ string-in-dsa-length,
+ string-in-dsa-iterate,
+ string-in-dsa-max-min,
+ string-in-dsa-program,
+ string-in-dsa-code,
+ string-in-dsa-js,
+ string-in-dsa-java,
+ string-in-dsa-python,
+ string-in-dsa-c,
+ string-in-dsa-cpp,
+ string-in-dsa-ts,
+ ]
+---
+
+A string is a sequence of characters. It is a data structure that represents a sequence of characters, either as a literal constant or as some kind of variable. In data structures and algorithms, strings are used in a wide range of applications such as text processing, pattern matching, and data serialization.
+
+## Why are Strings important?
+
+Strings are important because they are used to store and manipulate text. They are used in many applications such as text processing, pattern matching, and data serialization.
+
+## How to declare a String?
+
+A string can be declared in various programming languages using the following syntax:
+
+# Strings in Data Structures and Algorithms (DSA)
+
+## Table of Contents
+
+1. [Introduction](#introduction)
+2. [Basic String Operations](#basic-string-operations)
+3. [Pattern Matching Algorithms](#pattern-matching-algorithms)
+4. [String Manipulation](#string-manipulation)
+5. [String Data Structures](#string-data-structures)
+6. [Common String Problems](#common-string-problems)
+7. [Advanced String Algorithms](#advanced-string-algorithms)
+8. [Resources and References](#resources-and-references)
+
+## Introduction
+
+Strings are sequences of characters and are a fundamental data type in computer science. They are used extensively in algorithms and data structures.
+
+## Basic String Operations
+
+- **Length**: Determine the length of a string.
+- **Concatenation**: Combine two or more strings.
+- **Substring**: Extract a portion of a string.
+- **Comparison**: Compare two strings lexicographically.
+- **Search**: Find the occurrence of a substring.
+
+## Pattern Matching Algorithms
+
+- **Naive Pattern Matching**: A straightforward approach with a time complexity of O(m\*n).
+- **Knuth-Morris-Pratt (KMP)**: An efficient pattern matching algorithm with a time complexity of O(m+n).
+- **Rabin-Karp Algorithm**: Uses hashing for pattern matching with a time complexity of O(m+n) on average.
+- **Boyer-Moore Algorithm**: A powerful algorithm with a worst-case time complexity of O(m\*n) but performs well in practice.
+
+## String Manipulation
+
+- **Reversal**: Reversing a string.
+- **Palindromes**: Checking if a string reads the same forwards and backwards.
+- **Anagrams**: Checking if two strings are permutations of each other.
+- **Rotation**: Rotating a string by a given number of characters.
+
+## String Data Structures
+
+- **Trie (Prefix Tree)**: A tree-like data structure that stores a dynamic set of strings, typically used for search operations.
+- **Suffix Tree**: A compressed trie of all suffixes of a given string, useful for pattern matching.
+- **Suffix Array**: An array of all suffixes of a string, sorted in lexicographical order.
+- **Aho-Corasick Algorithm**: A trie-based data structure for multiple pattern matching.
+
+## Common String Problems
+
+- **Longest Common Substring**: Finding the longest substring that appears in two or more strings.
+- **Longest Common Subsequence**: Finding the longest sequence that can be derived from two strings without changing the order of characters.
+- **Edit Distance (Levenshtein Distance)**: Measuring the minimum number of single-character edits required to change one string into another.
+- **String Compression**: Reducing the size of a string using algorithms like Run-Length Encoding (RLE).
+
+## Advanced String Algorithms
+
+- **Burrows-Wheeler Transform (BWT)**: A data transformation algorithm useful for data compression.
+- **Manacher’s Algorithm**: An efficient algorithm to find the longest palindromic substring in linear time.
+- **Z-Algorithm**: Finds occurrences of a pattern in a string in linear time.
+
+## Resources and References
+
+- **Books**:
+ - "Introduction to Algorithms" by Cormen, Leiserson, Rivest, and Stein
+ - "Algorithms" by Robert Sedgewick and Kevin Wayne
+- **Online Courses**:
+ - Coursera: Data Structures and Algorithm Specialization
+ - edX: Algorithms and Data Structures
+- **Websites**:
+ - [GeeksforGeeks](https://www.geeksforgeeks.org)
+ - [LeetCode](https://leetcode.com)
+ - [HackerRank](https://www.hackerrank.com)
+
+---
+
+By understanding and mastering these string concepts and algorithms, you will be well-equipped to tackle a wide range of problems in data structures and algorithms.
+
+## Conclusion
+
+Strings are a vital data structure in the study of data structures and algorithms (DSA). They are sequences of characters used to represent text and are fundamental to various programming tasks. In this tutorial, we explored the essential operations related to strings, including declaration, access, modification, length determination, iteration, and searching in different programming languages like JavaScript, Java, Python, C, C++, and TypeScript.
+
+Understanding strings is crucial for solving numerous problems in computer science, from simple text manipulation to complex algorithms in text processing, pattern matching, and more. The examples provided demonstrate how to work with strings efficiently, ensuring a robust foundation for tackling more advanced DSA concepts. Mastery of strings enhances your ability to handle data and perform operations crucial in both everyday programming and competitive coding.
+
+Problems for Practice
+To further practice and test your understanding of strings, consider solving the following problems from LeetCode:
+
+1. Longest Substring Without Repeating Characters
+2. Valid Anagram
+3. Longest Palindromic Substring
+4. Group Anagrams
+5. Minimum Window Substring
+
+Engaging with these problems will help reinforce the concepts learned and provide practical experience in using strings effectively. By practicing these problems, you will enhance your problem-solving skills and deepen your understanding of string manipulation in various contexts.
diff --git a/dsa-solutions/lc-solutions/0000-0099/0017-Letter-Combinations-of-a-Phone-Number.md b/dsa-solutions/lc-solutions/0000-0099/0017-Letter-Combinations-of-a-Phone-Number.md
index de07f5ca6..fd6fed234 100644
--- a/dsa-solutions/lc-solutions/0000-0099/0017-Letter-Combinations-of-a-Phone-Number.md
+++ b/dsa-solutions/lc-solutions/0000-0099/0017-Letter-Combinations-of-a-Phone-Number.md
@@ -1,7 +1,7 @@
---
-id: Letter Combinations of a Phone Number
+id: letter-combinations-of-a-phone-number
title: Letter Combinations of a Phone Number (LeetCode)
-sidebar_label: 0017-Letter-Combinations-of-a-Phone-Number
+sidebar_label: 0017 Letter Combinations of a Phone Number
tags:
- Back Tracking
- Mapping
@@ -39,6 +39,7 @@ Given a string containing digits from 2-9 inclusive, return all possible letter
- **Output:** `["a","b","c"]`
### Constraints:
+
- `0 ≤ digits.length ≤ 4`
- `0 ≤ digits.length ≤ 4digits[𝑖]`
- `digits[i] is a digit in the range ['2', '9'].`
@@ -313,4 +314,4 @@ Here's a step-by-step algorithm for generating all possible letter combinations
- Call the backtracking function with the initial index set to 0 and an empty string as the initial combination.
- Return the list of combinations.
-This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking.
\ No newline at end of file
+This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking.
From 694dbce666abb6064a836d3ae60c30a5b8bb7cc1 Mon Sep 17 00:00:00 2001
From: Sadaf <137484958+SadafKausar2025@users.noreply.github.com>
Date: Mon, 10 Jun 2024 15:50:24 +0530
Subject: [PATCH 2/2] added more
---
docs/dsa/strings/strings-dsa.md | 212 ++++++++++++++++++++++++++++++++
1 file changed, 212 insertions(+)
diff --git a/docs/dsa/strings/strings-dsa.md b/docs/dsa/strings/strings-dsa.md
index cc0d595af..a37e5923a 100644
--- a/docs/dsa/strings/strings-dsa.md
+++ b/docs/dsa/strings/strings-dsa.md
@@ -71,6 +71,218 @@ Strings are sequences of characters and are a fundamental data type in computer
- **Comparison**: Compare two strings lexicographically.
- **Search**: Find the occurrence of a substring.
+## Why are Strings important?
+
+Strings are important because they are used to store and manipulate text. They are used in many applications such as text processing, pattern matching, and data serialization.
+
+## How to declare a String?
+
+A string can be declared in various programming languages using the following syntax:
+
+
+
+
+ ```js
+ // Declare a string in JavaScript
+ let str = "Hello, world!";
+ ```
+
+
+
+ ```java
+ // Declare a string in Java
+ String str = "Hello, world!";
+ ```
+
+
+
+ ```python
+ # Declare a string in Python
+ str = "Hello, world!"
+ ```
+
+
+
+ ```c
+ // Declare a string in C
+ char str[] = "Hello, world!";
+ ```
+
+
+
+ ```cpp
+ // Declare a string in C++
+ std::string str = "Hello, world!";
+ ```
+
+
+
+ ```ts
+ // Declare a string in TypeScript
+ let str: string = "Hello, world!";
+ ```
+
+
+
+## How to access a String?
+
+A string can be accessed using the index of the character. The index of the first character is 0, the index of the second character is 1, and so on.
+
+
+
+
+ ```js
+ // Access a string in JavaScript
+ let str = "Hello, world!";
+ console.log(str[0]); // H
+ console.log(str[1]); // e
+ console.log(str[2]); // l
+ ```
+
+
+
+ ```java
+ // Access a string in Java
+ String str = "Hello, world!";
+ System.out.println(str.charAt(0)); // H
+ System.out.println(str.charAt(1)); // e
+ System.out.println(str.charAt(2)); // l
+ ```
+
+
+
+ ```python
+ # Access a string in Python
+ str = "Hello, world!"
+ print(str[0]) # H
+ print(str[1]) # e
+ print(str[2]) # l
+ ```
+
+
+
+ ```c
+ // Access a string in C
+ char str[] = "Hello, world!";
+ printf("%c\n", str[0]); // H
+ printf("%c\n", str[1]); // e
+ printf("%c\n", str[2]); // l
+ ```
+
+
+
+ ```cpp
+ // Access a string in C++
+ std::string str = "Hello, world!";
+ std::cout << str[0] << std::endl; // H
+ std::cout << str[1] << std::endl; // e
+ std::cout << str[2] << std::endl; // l
+ ```
+
+
+
+ ```ts
+ // Access a string in TypeScript
+ let str: string = "Hello, world!";
+ console.log(str[0]); // H
+ console.log(str[1]); // e
+ console.log(str[2]); // l
+ ```
+
+
+
+## How to update a String?
+
+A string can be updated by creating a new string with the desired changes, as strings are immutable in many programming languages.
+
+
+
+
+ ```js
+ // Update a string in JavaScript
+ let str = "Hello, world!";
+ str = "Hello, JavaScript!";
+ console.log(str); // Hello, JavaScript!
+ ```
+
+
+
+ ```java
+ // Update a string in Java
+ String str = "Hello, world!";
+ str = "Hello, Java!";
+ System.out.println(str); // Hello, Java!
+ ```
+
+
+
+ ```python
+ # Update a string in Python
+ str = "Hello, world!"
+ str = "Hello, Python!"
+ print(str) # Hello, Python!
+ ```
+
+
+
+ ```c
+ // Update a string in C
+ char str[] = "Hello, world!";
+ strcpy(str, "Hello, C!");
+ printf("%s\n", str); // Hello, C!
+ ```
+
+
+
+ ```cpp
+ // Update a string in C++
+ std::string str = "Hello, world!";
+ str = "Hello, C++!";
+ std::cout << str << std::endl; // Hello, C++!
+ ```
+
+
+
+ ```ts
+ // Update a string in TypeScript
+ let str: string = "Hello, world!";
+ str = "Hello, TypeScript!";
+ console.log(str); // Hello, TypeScript!
+ ```
+
+
+
+## How to find the length of a String?
+
+The length of a string can be found using the `length` property or method.
+
+
+
+
+ ```js
+ // Find the length of a string in JavaScript
+ let str = "Hello, world!";
+ console.log(str.length); // 13
+ ```
+
+
+
+ ```java
+ // Find the length of a string in Java
+ String str = "Hello, world!";
+ System.out.println(str.length()); // 13
+ ```
+
+
+
+ ```python
+ # Find the length of a string in Python
+ str = "Hello, world!"
+ print(len(str)) # 13
+ ```
+
+
+
## Pattern Matching Algorithms
- **Naive Pattern Matching**: A straightforward approach with a time complexity of O(m\*n).