Skip to content

Commit ba973b5

Browse files
committed
awseq
1 parent a1bad9c commit ba973b5

10 files changed

Lines changed: 255 additions & 19 deletions

File tree

DailyLeetCode/MaximumOrderedTriplet.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,34 @@ public static long MaximumTripletValue_MaxQueue(int[] nums)
66
{
77

88
if (nums.Length < 3) return 0;
9-
var maxQueue = new PriorityQueue<int[], long>(comparer: Comparer<long>.Create(((i, i1) => (i < i1) ? 1 : -1)));
10-
9+
var maxValue = long.MinValue;
1110
for (int i = 0; i < nums.Length; i++)
1211
{
1312
for (int j = i+1; j < nums.Length; j++)
1413
{
1514
for (int k = j+1; k < nums.Length; k++)
1615
{
1716
long val = (nums[i] - nums[j]) * (long) nums[k];
18-
maxQueue.Enqueue([i,j,k], val);
17+
maxValue = Math.Max(maxValue, val);
1918
}
2019
}
2120
}
2221

23-
var max = maxQueue.Dequeue();
24-
long value = (nums[max[0]] - nums[max[1]]) * (long)nums[max[2]];
25-
return value < 0 ? 0 : value;
22+
return maxValue < 0 ? 0 : maxValue;
2623
}
2724

2825
public static long MaximumTripletValue_PrefixSum(int[] nums)
2926
{
27+
if (nums.Length < 3) return 0;
28+
29+
var maxVal = long.MinValue;
30+
31+
for (int i = 0; i < nums.Length; i++)
32+
{
33+
34+
}
35+
36+
3037
return 0;
3138
}
3239
}

LeetCodePatterns.sln

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Math", "Math\Math\Math.cspr
4747
EndProject
4848
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Math.Test", "Math\Math.Test\Math.Test.csproj", "{EB36BCDD-02D6-457A-BA3E-A42F6A8544D3}"
4949
EndProject
50-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DFS", "Graph\DFS\DFS.csproj", "{34F1DA0D-5897-44D4-AC31-CBFA654D47D7}"
50+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Trie", "Trie", "{A8C21554-86B0-4BB7-B8CA-E829C186D5ED}"
5151
EndProject
52-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Graph", "Graph", "{E7AADF05-AF2E-4A54-ACFB-0F8A971BD528}"
52+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trie", "Trie\Trie\Trie.csproj", "{D60CFD58-2A02-48CB-A8F9-81A3132D6370}"
5353
EndProject
54-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BFS", "Graph\BFS\BFS.csproj", "{6FD5F7B1-4A40-408E-8BF3-DA89C0873045}"
55-
EndProject
56-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DataStructures", "DataStructures", "{2590E36B-A3E2-41EC-8A85-C79D3B72DEC5}"
57-
EndProject
58-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStructures", "DataStructures\DataStructures\DataStructures.csproj", "{BF171E67-B282-4BD8-9511-D4218BDA8BD4}"
59-
EndProject
60-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Graphs", "Graph\Graphs\Graphs.csproj", "{AC86D8BA-7B66-40D6-9351-870BBE35457F}"
54+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trie.Tests", "Trie\Trie.Tests\Trie.Tests.csproj", "{794C4875-0648-4850-9A2B-90CDF5D0DC32}"
6155
EndProject
6256
Global
6357
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -131,6 +125,14 @@ Global
131125
{AC86D8BA-7B66-40D6-9351-870BBE35457F}.Debug|Any CPU.Build.0 = Debug|Any CPU
132126
{AC86D8BA-7B66-40D6-9351-870BBE35457F}.Release|Any CPU.ActiveCfg = Release|Any CPU
133127
{AC86D8BA-7B66-40D6-9351-870BBE35457F}.Release|Any CPU.Build.0 = Release|Any CPU
128+
{D60CFD58-2A02-48CB-A8F9-81A3132D6370}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
129+
{D60CFD58-2A02-48CB-A8F9-81A3132D6370}.Debug|Any CPU.Build.0 = Debug|Any CPU
130+
{D60CFD58-2A02-48CB-A8F9-81A3132D6370}.Release|Any CPU.ActiveCfg = Release|Any CPU
131+
{D60CFD58-2A02-48CB-A8F9-81A3132D6370}.Release|Any CPU.Build.0 = Release|Any CPU
132+
{794C4875-0648-4850-9A2B-90CDF5D0DC32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
133+
{794C4875-0648-4850-9A2B-90CDF5D0DC32}.Debug|Any CPU.Build.0 = Debug|Any CPU
134+
{794C4875-0648-4850-9A2B-90CDF5D0DC32}.Release|Any CPU.ActiveCfg = Release|Any CPU
135+
{794C4875-0648-4850-9A2B-90CDF5D0DC32}.Release|Any CPU.Build.0 = Release|Any CPU
134136
EndGlobalSection
135137
GlobalSection(SolutionProperties) = preSolution
136138
HideSolutionNode = FALSE
@@ -149,10 +151,8 @@ Global
149151
{4EB8C5B8-6669-4170-BB50-12B2F4119559} = {E57C75C9-260A-4BEA-BE27-02C0A2EDE2C8}
150152
{7CC71E5D-5D18-4E0B-897D-E5FD5D5131D3} = {B20F5F9A-5FD0-4C28-AD4F-28CC0591F530}
151153
{EB36BCDD-02D6-457A-BA3E-A42F6A8544D3} = {B20F5F9A-5FD0-4C28-AD4F-28CC0591F530}
152-
{34F1DA0D-5897-44D4-AC31-CBFA654D47D7} = {E7AADF05-AF2E-4A54-ACFB-0F8A971BD528}
153-
{6FD5F7B1-4A40-408E-8BF3-DA89C0873045} = {E7AADF05-AF2E-4A54-ACFB-0F8A971BD528}
154-
{BF171E67-B282-4BD8-9511-D4218BDA8BD4} = {2590E36B-A3E2-41EC-8A85-C79D3B72DEC5}
155-
{AC86D8BA-7B66-40D6-9351-870BBE35457F} = {E7AADF05-AF2E-4A54-ACFB-0F8A971BD528}
154+
{D60CFD58-2A02-48CB-A8F9-81A3132D6370} = {A8C21554-86B0-4BB7-B8CA-E829C186D5ED}
155+
{794C4875-0648-4850-9A2B-90CDF5D0DC32} = {A8C21554-86B0-4BB7-B8CA-E829C186D5ED}
156156
EndGlobalSection
157157
GlobalSection(ExtensibilityGlobals) = postSolution
158158
SolutionGuid = {86DEDE4A-7156-45A1-BEB3-3C62CF81256E}

Leetcode/11-07-2025.md

Whitespace-only changes.

Leetcode/1989.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
2+
```python
3+
def catchMaxAmountOfPeople(team: List[int], dist: int) -> int:
4+
it = []
5+
6+
for i, t in enumerate(team):
7+
if t == 1:
8+
it.append(i)
9+
10+
seen = set()
11+
12+
for idx in it:
13+
low, high = idx - dist, idx + dist
14+
for j in range(low, high+1):
15+
if j >= len(team):
16+
j = j % len(team)
17+
18+
if team[j] == 0:
19+
seen.add(j)
20+
break
21+
return len(seen)
22+
```
23+
24+
N^2
25+
[1,1,0,1,0,1]
26+
dist =2
27+
exp = 2
28+
act=3
29+
will not work
30+
31+
also
32+
33+
```python
34+
def catchMaxAmountOfPeople(team: List[int], dist: int) -> int:
35+
it = []
36+
z = sortedList()
37+
38+
for i, t in enumerate(team):
39+
if t == 1:
40+
it.append(i)
41+
else:
42+
z.add(i)
43+
seen = set()
44+
45+
for idx in it:
46+
low, high = idx - dist, idx + dist
47+
for h in z:
48+
if low <= h <= high and h not in seen:
49+
seen.add(h)
50+
z.discard(h)
51+
break
52+
53+
return len(seen)
54+
```
55+
56+
most likely
57+
58+
59+
```python
60+
def catchMaxAmountOfPeople(team: List[int], dist: int) -> int:
61+
it = []
62+
63+
for i, t in enumerate(team):
64+
if t == 1:
65+
it.append(i)
66+
67+
seen = set()
68+
69+
for idx in it:
70+
low, high = idx - dist, idx + dist
71+
b = bisect_lef(z, low)
72+
if b < len(z):
73+
val = z[b]
74+
75+
if low <= val <= high and val not in seen:
76+
seen.add(val)
77+
z.discard(val)
78+
return len(seen)
79+
```
80+
81+
```python
82+
def catchMaximumAmountofPeople(self, team: List[int], dist: int) -> int:
83+
ans = j = 0
84+
n = len(team)
85+
for i, x in enumerate(team):
86+
if x:
87+
while j < n and (team[j] or i - j > dist):
88+
j += 1
89+
if j < n and abs(i - j) <= dist:
90+
ans += 1
91+
j += 1
92+
return ans
93+
```
94+
95+
```python
96+
def catchMaximumAmountofPeople(self, team: List[int], dist: int) -> int:
97+
ans = j = 0
98+
n = len(team)
99+
for i, x in enumerate(team):
100+
if x:
101+
while j < n and (team[j] or i - j > dist):
102+
j += 1
103+
if j < n and abs(i - j) <= dist:
104+
ans += 1
105+
j += 1
106+
return ans
107+
```

Leetcode/Untitled.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
workcenterId = 56

Leetcode/Welcome.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This is your new *vault*.
2+
3+
Make a note of something, [[create a link]], or try [the Importer](https://help.obsidian.md/Plugins/Importer)!
4+
5+
When you're ready, delete this note and make the vault your own.

Trie/Trie.Tests/Trie.Tests.csproj

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
15+
<PackageReference Include="xunit" Version="2.5.3"/>
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<Using Include="Xunit"/>
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\Trie\Trie.csproj" />
25+
</ItemGroup>
26+
27+
</Project>

Trie/Trie.Tests/UnitTest1.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Trie.Tests;
2+
3+
public class UnitTest1
4+
{
5+
[Theory]
6+
[InlineData(new int[] {1,10,100 }, new int[] { 1000 }, 3)]
7+
public void AllShouldPass(int[] arr1, int[] arr2, int expected)
8+
{
9+
var actual = TrieImplementation.LongestCommonPrefix(arr1, arr2);
10+
11+
Assert.Equal(expected, actual);
12+
}
13+
}

Trie/Trie/Class1.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
namespace Trie;
2+
public class TrieNode
3+
{
4+
public bool IsWord { get; set; }
5+
public Dictionary<int, TrieNode> Children { get; } = new Dictionary<int, TrieNode>();
6+
}
7+
public class TrieImplementation
8+
{
9+
private static readonly TrieNode _root = new TrieNode();
10+
11+
public static int[] GetArray(int number)
12+
{
13+
var list = new List<int>();
14+
15+
while (number / 10 != 0)
16+
{
17+
list.Add(number % 10);
18+
number /= 10;
19+
}
20+
list.Reverse();
21+
22+
return list.ToArray();
23+
}
24+
public static int LongestCommonPrefix(int[] arr1, int[] arr2)
25+
{
26+
foreach (var i in arr1)
27+
{
28+
AddWord(i);
29+
}
30+
31+
var max = 0;
32+
foreach(var i in arr2)
33+
{
34+
var nums = GetArray(i);
35+
var curr = Search(nums);
36+
max = Math.Max(max, curr);
37+
}
38+
39+
return max;
40+
}
41+
42+
public static void AddWord(int number)
43+
{
44+
var nums = GetArray(number);
45+
var node = _root;
46+
foreach (int c in nums)
47+
{
48+
if (!node.Children.ContainsKey(c))
49+
node.Children[c] = new TrieNode();
50+
node = node.Children[c];
51+
}
52+
node.IsWord = true;
53+
}
54+
public static int Search(int[] word)
55+
{
56+
var node = _root;
57+
var depth = 0;
58+
foreach (var c in word)
59+
{
60+
if (!node.Children.TryGetValue(c, out var child))
61+
return depth+1;
62+
node = child;
63+
depth++;
64+
}
65+
return depth;
66+
}
67+
}

Trie/Trie/Trie.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)