Skip to content

Commit 8a8919f

Browse files
Zanger67/leetcodeZanger67/leetcode
authored andcommitted
Updated markdown files
1 parent 0458a16 commit 8a8919f

File tree

10 files changed

+79
-8
lines changed

10 files changed

+79
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# **[LeetCode Records](https://leetcode.com/u/Zanger/)** (642 solved)
1+
# **[LeetCode Records](https://leetcode.com/u/Zanger/)** (643 solved)
22

33
<!-- This readme was generated using [WikiLeet](<https://github.com/Zanger67/WikiLeet>) -->
44

@@ -362,6 +362,7 @@ This repo is a collection of my LeetCode solutions, primarily written in Python,
362362
| 1166 | [Design File System](<https://leetcode.com/problems/design-file-system>) | Medium | Weekly Premium | [solution](<markdowns/_1166. Design File System.md>) | py |
363363
| 1171 | [Remove Zero Sum Consecutive Nodes from Linked List](<https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list>) | Medium | | [solution](<markdowns/_1171. Remove Zero Sum Consecutive Nodes from Linked List.md>) | py |
364364
| 1181 | [Before and After Puzzle](<https://leetcode.com/problems/before-and-after-puzzle>) | Medium | Weekly Premium | [solution](<markdowns/_1181. Before and After Puzzle.md>) | py |
365+
| 1182 | [Shortest Distance to Target Color](<https://leetcode.com/problems/shortest-distance-to-target-color>) | Medium | Weekly Premium | [solution](<markdowns/_1182. Shortest Distance to Target Color.md>) | py |
365366
| 1184 | [Distance Between Bus Stops](<https://leetcode.com/problems/distance-between-bus-stops>) | Easy | | [solution](<markdowns/_1184. Distance Between Bus Stops.md>) | py |
366367
| 1190 | [Reverse Substrings Between Each Pair of Parentheses](<https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses>) | Medium | Daily | [solution](<markdowns/_1190. Reverse Substrings Between Each Pair of Parentheses.md>) | py |
367368
| 1198 | [Find Smallest Common Element in All Rows](<https://leetcode.com/problems/find-smallest-common-element-in-all-rows>) | Medium | | [solution](<markdowns/_1198. Find Smallest Common Element in All Rows.md>) | py |

markdowns/Medium.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Medium Questions (413)
1+
# Medium Questions (414)
22

33
*[Back to top](<../README.md>)*
44

@@ -210,6 +210,7 @@
210210
| 1166 | [Design File System](<https://leetcode.com/problems/design-file-system>) | Medium | Weekly Premium | [solution](<_1166. Design File System.md>) | py | Jun 28, 2024 |
211211
| 1171 | [Remove Zero Sum Consecutive Nodes from Linked List](<https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list>) | Medium | | [solution](<_1171. Remove Zero Sum Consecutive Nodes from Linked List.md>) | py | Jun 15, 2024 |
212212
| 1181 | [Before and After Puzzle](<https://leetcode.com/problems/before-and-after-puzzle>) | Medium | Weekly Premium | [solution](<_1181. Before and After Puzzle.md>) | py | Aug 24, 2025 |
213+
| 1182 | [Shortest Distance to Target Color](<https://leetcode.com/problems/shortest-distance-to-target-color>) | Medium | Weekly Premium | [solution](<_1182. Shortest Distance to Target Color.md>) | py | Aug 29, 2025 |
213214
| 1190 | [Reverse Substrings Between Each Pair of Parentheses](<https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses>) | Medium | Daily | [solution](<_1190. Reverse Substrings Between Each Pair of Parentheses.md>) | py | Jul 11, 2024 |
214215
| 1198 | [Find Smallest Common Element in All Rows](<https://leetcode.com/problems/find-smallest-common-element-in-all-rows>) | Medium | | [solution](<_1198. Find Smallest Common Element in All Rows.md>) | py | Aug 26, 2025 |
215216
| 1209 | [Remove All Adjacent Duplicates in String II](<https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii>) | Medium | | [solution](<_1209. Remove All Adjacent Duplicates in String II.md>) | py | Jun 19, 2024 |

markdowns/Questions_By_Code_Length.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ Calculations are based on the code files's byte sizes.
298298
| 735 | [Asteroid Collision](<https://leetcode.com/problems/asteroid-collision>) | Medium | | [solution](<_735. Asteroid Collision.md>) | py | Jul 14, 2024 |
299299
| 2679 | [Sum in a Matrix](<https://leetcode.com/problems/sum-in-a-matrix>) | Medium | | [solution](<_2679. Sum in a Matrix.md>) | java | May 22, 2024 |
300300
| 2723 | [Add Two Promises](<https://leetcode.com/problems/add-two-promises>) | Easy | | [solution](<_2723. Add Two Promises.md>) | js | Jul 09, 2024 |
301+
| 1182 | [Shortest Distance to Target Color](<https://leetcode.com/problems/shortest-distance-to-target-color>) | Medium | Weekly Premium | [solution](<_1182. Shortest Distance to Target Color.md>) | py | Aug 29, 2025 |
301302
| 208 | [Implement Trie (Prefix Tree)](<https://leetcode.com/problems/implement-trie-prefix-tree>) | Medium | B75, N150 | [solution](<_208. Implement Trie (Prefix Tree).md>) | py | Jun 27, 2024 |
302303
| 784 | [Letter Case Permutation](<https://leetcode.com/problems/letter-case-permutation>) | Medium | | [solution](<_784. Letter Case Permutation.md>) | py | Jun 15, 2024 |
303304
| 272 | [Closest Binary Search Tree Value II](<https://leetcode.com/problems/closest-binary-search-tree-value-ii>) | Hard | Weekly Premium | [solution](<_272. Closest Binary Search Tree Value II.md>) | py | Jul 01, 2024 |

markdowns/Questions_By_Recent.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Calculations are based on the date of the first solve.
66

77
| # | Title | Level | Cats | Solution | Languages | Date Complete |
88
|-----:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------|:--------------------------|:----------------------------------------------------------------------------------------------------|:--------------------------------------------|:----------------|
9+
| 1182 | [Shortest Distance to Target Color](<https://leetcode.com/problems/shortest-distance-to-target-color>) | Medium | Weekly Premium | [solution](<_1182. Shortest Distance to Target Color.md>) | py | Aug 29, 2025 |
910
| 3021 | [Alice and Bob Playing Flower Game](<https://leetcode.com/problems/alice-and-bob-playing-flower-game>) | Medium | Daily | [solution](<_3021. Alice and Bob Playing Flower Game.md>) | go, py | Aug 29, 2025 |
1011
| 122 | [Best Time to Buy and Sell Stock II](<https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii>) | Medium | | [solution](<_122. Best Time to Buy and Sell Stock II.md>) | py | Aug 27, 2025 |
1112
| 792 | [Number of Matching Subsequences](<https://leetcode.com/problems/number-of-matching-subsequences>) | Medium | | [solution](<_792. Number of Matching Subsequences.md>) | py | Aug 27, 2025 |

markdowns/Topics.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
------
66

7-
- [Array](<by_topic/Array.md>) (323 completed)
7+
- [Array](<by_topic/Array.md>) (324 completed)
88
- [String](<by_topic/String.md>) (150 completed)
99
- [Hash Table](<by_topic/Hash Table.md>) (145 completed)
1010
- [Depth-First Search](<by_topic/Depth-First Search.md>) (105 completed)
@@ -14,13 +14,13 @@
1414
- [Sorting](<by_topic/Sorting.md>) (76 completed)
1515
- [Breadth-First Search](<by_topic/Breadth-First Search.md>) (73 completed)
1616
- [Two Pointers](<by_topic/Two Pointers.md>) (61 completed)
17-
- [Dynamic Programming](<by_topic/Dynamic Programming.md>) (58 completed)
17+
- [Dynamic Programming](<by_topic/Dynamic Programming.md>) (59 completed)
1818
- [Matrix](<by_topic/Matrix.md>) (56 completed)
1919
- [Stack](<by_topic/Stack.md>) (56 completed)
2020
- [Greedy](<by_topic/Greedy.md>) (51 completed)
2121
- [Linked List](<by_topic/Linked List.md>) (45 completed)
2222
- [Simulation](<by_topic/Simulation.md>) (44 completed)
23-
- [Binary Search](<by_topic/Binary Search.md>) (37 completed)
23+
- [Binary Search](<by_topic/Binary Search.md>) (38 completed)
2424
- [Design](<by_topic/Design.md>) (37 completed)
2525
- [Bit Manipulation](<by_topic/Bit Manipulation.md>) (36 completed)
2626
- [Counting](<by_topic/Counting.md>) (34 completed)

markdowns/Weekly_Questions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Dates are for the date I completed the question so due to the my time zone and h
66

77
| # | Title | Level | Cats | Solution | Languages | Date Complete |
88
|-----:|:---------------------------------------------------------------------------------------------------------------------------------------------------|:--------|:--------------------------|:-------------------------------------------------------------------------------|:------------|:----------------|
9+
| 1182 | [Shortest Distance to Target Color](<https://leetcode.com/problems/shortest-distance-to-target-color>) | Medium | Weekly Premium | [solution](<_1182. Shortest Distance to Target Color.md>) | py | Aug 29, 2025 |
910
| 1181 | [Before and After Puzzle](<https://leetcode.com/problems/before-and-after-puzzle>) | Medium | Weekly Premium | [solution](<_1181. Before and After Puzzle.md>) | py | Aug 22, 2025 |
1011
| 1166 | [Design File System](<https://leetcode.com/problems/design-file-system>) | Medium | Weekly Premium | [solution](<_1166. Design File System.md>) | py | Aug 15, 2025 |
1112
| 314 | [Binary Tree Vertical Order Traversal](<https://leetcode.com/problems/binary-tree-vertical-order-traversal>) | Medium | Weekly Premium | [solution](<_314. Binary Tree Vertical Order Traversal.md>) | py | Aug 01, 2025 |
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# 1182. [Shortest Distance to Target Color](<https://leetcode.com/problems/shortest-distance-to-target-color>)
2+
3+
*All prompts are owned by LeetCode. To view the prompt, click the title link above.*
4+
5+
*[Back to top](<../README.md>)*
6+
7+
------
8+
9+
> *First completed : August 29, 2025*
10+
>
11+
> *Last updated : August 29, 2025*
12+
13+
------
14+
15+
> **Related Topics** : **[Array](<by_topic/Array.md>), [Binary Search](<by_topic/Binary Search.md>), [Dynamic Programming](<by_topic/Dynamic Programming.md>)**
16+
>
17+
> **Acceptance Rate** : **55.54 %**
18+
19+
------
20+
21+
> ## V1 Fuzzy Binary Search
22+
>
23+
> Stored where each color appeared in sorted order then used binary search to approximately find where the value would be. Checked for the min difference for the found index j +/- 1 in case the exact value wasn't found (min_distance(arr[j - 1:j+1]) inclusive).
24+
>
25+
26+
------
27+
28+
## Solutions
29+
30+
- [m1182 v1.py](<../my-submissions/m1182 v1.py>)
31+
### Python
32+
#### [m1182 v1.py](<../my-submissions/m1182 v1.py>)
33+
```Python
34+
class Solution:
35+
def shortestDistanceColor(self, colors: List[int], queries: List[List[int]]) -> List[int]:
36+
indices = {1: [], 2: [], 3:[]}
37+
for i, c in enumerate(colors) :
38+
indices[c].append(i)
39+
40+
return [
41+
0 if colors[i] == c else self._bin_search_closest(indices[c], i)
42+
for i, c in queries
43+
]
44+
45+
def _bin_search_closest(self, arr: List[int], target_indx: int) -> int :
46+
if not arr :
47+
return -1
48+
l, r = 0, len(arr) - 1
49+
50+
while l < r :
51+
mid = (l + r) // 2
52+
mid_val = arr[mid]
53+
if mid_val == target_indx :
54+
return 0
55+
if mid_val > target_indx :
56+
r = mid - 1
57+
continue
58+
l = mid + 1
59+
60+
# Fuzzy bound so check +/- 1 index to see if it's an approximation
61+
return min(abs(target_indx - x) for x in arr[max(0, l - 1):min(len(arr), r + 2)])
62+
```
63+

markdowns/by_topic/Array.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [Array](<https://leetcode.com/tag/Array/>) (323 completed)
1+
# [Array](<https://leetcode.com/tag/Array/>) (324 completed)
22

33
*[Back to top](<../../README.md>)*
44

@@ -151,6 +151,7 @@
151151
| 1151 | [Minimum Swaps to Group All 1's Together](<https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together>) | Medium | Weekly Premium | [solution](<../_1151. Minimum Swaps to Group All 1's Together.md>) | py | Mar 01, 2025 |
152152
| 1160 | [Find Words That Can Be Formed by Characters](<https://leetcode.com/problems/find-words-that-can-be-formed-by-characters>) | Easy | | [solution](<../_1160. Find Words That Can Be Formed by Characters.md>) | py | Sep 24, 2024 |
153153
| 1181 | [Before and After Puzzle](<https://leetcode.com/problems/before-and-after-puzzle>) | Medium | Weekly Premium | [solution](<../_1181. Before and After Puzzle.md>) | py | Aug 24, 2025 |
154+
| 1182 | [Shortest Distance to Target Color](<https://leetcode.com/problems/shortest-distance-to-target-color>) | Medium | Weekly Premium | [solution](<../_1182. Shortest Distance to Target Color.md>) | py | Aug 29, 2025 |
154155
| 1184 | [Distance Between Bus Stops](<https://leetcode.com/problems/distance-between-bus-stops>) | Easy | | [solution](<../_1184. Distance Between Bus Stops.md>) | py | May 31, 2024 |
155156
| 1198 | [Find Smallest Common Element in All Rows](<https://leetcode.com/problems/find-smallest-common-element-in-all-rows>) | Medium | | [solution](<../_1198. Find Smallest Common Element in All Rows.md>) | py | Aug 26, 2025 |
156157
| 1207 | [Unique Number of Occurrences](<https://leetcode.com/problems/unique-number-of-occurrences>) | Easy | | [solution](<../_1207. Unique Number of Occurrences.md>) | py | Sep 25, 2024 |

0 commit comments

Comments
 (0)