From cfc919e82729be3aa21d047999819226994e96e1 Mon Sep 17 00:00:00 2001 From: ranveersingh2718 Date: Sat, 22 Nov 2025 15:21:37 -0800 Subject: [PATCH 1/2] fix c# param type, maximum-distance-in-arrays.md --- articles/maximum-distance-in-arrays.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/articles/maximum-distance-in-arrays.md b/articles/maximum-distance-in-arrays.md index 281479544..3f8e76cc1 100644 --- a/articles/maximum-distance-in-arrays.md +++ b/articles/maximum-distance-in-arrays.md @@ -79,7 +79,7 @@ class Solution { ```csharp public class Solution { - public int MaxDistance(List> arrays) { + public int MaxDistance(IList> arrays) { int res = 0; int n = arrays.Count; for (int i = 0; i < n - 1; i++) { @@ -212,8 +212,8 @@ class Solution { ```csharp public class Solution { - public int MaxDistance(List> arrays) { - List array1, array2; + public int MaxDistance(IList> arrays) { + IList array1, array2; int res = 0; int n = arrays.Count; for (int i = 0; i < n - 1; i++) { @@ -355,18 +355,20 @@ class Solution { ```csharp public class Solution { - public int MaxDistance(List> arrays) { + public int MaxDistance(IList> arrays) { int res = 0; int n = arrays[0].Count; int min_val = arrays[0][0]; int max_val = arrays[0][arrays[0].Count - 1]; + for (int i = 1; i < arrays.Count; i++) { n = arrays[i].Count; res = Math.Max(res, Math.Max(Math.Abs(arrays[i][n - 1] - min_val), - Math.Abs(max_val - arrays[i][0]))); + Math.Abs(max_val - arrays[i][0]))); min_val = Math.Min(min_val, arrays[i][0]); max_val = Math.Max(max_val, arrays[i][n - 1]); } + return res; } } From 90122e1f40b38a791ec33e1e3ddf141784980ee1 Mon Sep 17 00:00:00 2001 From: ranveersingh2718 Date: Sat, 22 Nov 2025 15:43:12 -0800 Subject: [PATCH 2/2] add add-bold-tag-in-string.md article --- articles/add-bold-tag-in-string.md | 161 +++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 articles/add-bold-tag-in-string.md diff --git a/articles/add-bold-tag-in-string.md b/articles/add-bold-tag-in-string.md new file mode 100644 index 000000000..8529c3243 --- /dev/null +++ b/articles/add-bold-tag-in-string.md @@ -0,0 +1,161 @@ +## 1. Mark Bold Characters + +::tabs-start + +```python +class Solution: + def addBoldTag(self, s: str, words: List[str]) -> str: + n = len(s) + bold = [False] * n + + for word in words: + start = s.find(word) + while start != -1: + for i in range(start, start + len(word)): + bold[i] = True + + start = s.find(word, start + 1) + + open_tag = "" + close_tag = "" + ans = [] + + for i in range(n): + if bold[i] and (i == 0 or not bold[i - 1]): + ans.append(open_tag) + + ans.append(s[i]) + + if bold[i] and (i == n - 1 or not bold[i + 1]): + ans.append(close_tag) + + return "".join(ans) +``` + +```java +class Solution { + public String addBoldTag(String s, String[] words) { + int n = s.length(); + boolean[] bold = new boolean[n]; + + for (String word: words) { + int start = s.indexOf(word); + while (start != -1) { + for (int i = start; i < start + word.length(); i++) { + bold[i] = true; + } + + start = s.indexOf(word, start + 1); + } + } + + String openTag = ""; + String closeTag = ""; + StringBuilder ans = new StringBuilder(); + + for (int i = 0; i < n; i++) { + if (bold[i] && (i == 0 || !bold[i - 1])) { + ans.append(openTag); + } + + ans.append(s.charAt(i)); + + if (bold[i] && (i == n - 1 || !bold[i + 1])) { + ans.append(closeTag); + } + } + + return ans.toString(); + } +} +``` + +```cpp +class Solution { +public: + string addBoldTag(string s, vector& words) { + int n = s.size(); + vector bold(n); + + for (string word: words) { + int start = s.find(word); + while (start != -1) { + for (int i = start; i < start + word.size(); i++) { + bold[i] = true; + } + + start = s.find(word, start + 1); + } + } + + string openTag = ""; + string closeTag = ""; + string ans = ""; + + for (int i = 0; i < n; i++) { + if (bold[i] && (i == 0 || !bold[i - 1])) { + ans += openTag; + } + + ans += s[i]; + + if (bold[i] && (i == n - 1 || !bold[i + 1])) { + ans += closeTag; + } + } + + return ans; + } +}; +``` + +```javascript +class Solution { + /** + * @param {string} s + * @param {string[]} words + * @return {string} + */ + addBoldTag(s, words) { + const n = s.length; + const bold = new Array(n).fill(false); + + for (const word of words) { + let start = s.indexOf(word); + while (start !== -1) { + for (let i = start; i < start + word.length; i++) { + bold[i] = true; + } + start = s.indexOf(word, start + 1); + } + } + + const openTag = ""; + const closeTag = ""; + const ans = []; + + for (let i = 0; i < n; i++) { + if (bold[i] && (i === 0 || !bold[i - 1])) { + ans.push(openTag); + } + ans.push(s[i]); + if (bold[i] && (i === n - 1 || !bold[i + 1])) { + ans.push(closeTag); + } + } + + return ans.join(""); + } +} +``` + +::tabs-end + +### Time & Space Complexity +The time complexity may differ between languages. It is dependent on how the built-in method is implemented. +For this analysis, we will assume that we are using Java. + +- Time complexity: $O(m \cdot (n^2 \cdot k - n \cdot k^2))$ +- Space complexity: $O(n)$ + +> Where $n$ is `s.length`, $m$ is `words.length`, and $k$ is the average length of the words.