Greatest Common Divisor¶
Table of Contents¶
- 1979. Find Greatest Common Divisor of Array (Easy)
- 2807. Insert Greatest Common Divisors in Linked List (Medium)
- 914. X of a Kind in a Deck of Cards (Easy)
- 1071. Greatest Common Divisor of Strings (Easy)
- 2344. Minimum Deletions to Make Array Divisible (Hard)
- 365. Water and Jug Problem (Medium)
- 858. Mirror Reflection (Medium)
- 2654. Minimum Number of Operations to Make All Array Elements Equal to 1 (Medium)
- 1250. Check If It Is a Good Array (Hard)
- 149. Max Points on a Line (Hard)
- 2607. Make K-Subarray Sums Equal (Medium)
- 2447. Number of Subarrays With GCD Equal to K (Medium)
- 2543. Check if Point Is Reachable (Hard)
- 2183. Count Array Pairs Divisible by K (Hard)
- 3312. Sorted GCD Pair Queries (Hard)
- 1819. Number of Different Subsequences GCDs (Hard)
- 2436. Minimum Split Into Subarrays With GCD Greater Than One (Medium) 👑
- 2464. Minimum Subarrays in a Valid Split (Medium) 👑
- 2941. Maximum GCD-Sum of a Subarray (Hard) 👑
1979. Find Greatest Common Divisor of Array¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: array, math, number theory
2807. Insert Greatest Common Divisors in Linked List¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: linked list, math, number theory
914. X of a Kind in a Deck of Cards¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: array, hash table, math, counting, number theory
1071. Greatest Common Divisor of Strings¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: math, string
2344. Minimum Deletions to Make Array Divisible¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, math, sorting, heap priority queue, number theory
365. Water and Jug Problem¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, depth first search, breadth first search
858. Mirror Reflection¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, geometry, number theory
2654. Minimum Number of Operations to Make All Array Elements Equal to 1¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, number theory
1250. Check If It Is a Good Array¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, math, number theory
149. Max Points on a Line¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, hash table, math, geometry
from collections import defaultdict
from typing import List
# GCD
def maxPoints(points: List[List[int]]) -> int:
n = len(points)
if n <= 2:
return n
res = 0
for i in range(n - 1):
x1, y1 = points[i]
cnt = defaultdict(int)
for j in range(i + 1, n):
x2, y2 = points[j]
g = "inf" if x1 == x2 else (y2 - y1) / (x2 - x1)
cnt[g] += 1
res = max(res, 1 + max(cnt.values()))
return res
points = [[1, 1], [3, 2], [5, 3], [4, 1], [2, 3], [1, 4]]
print(maxPoints(points)) # 4
2607. Make K-Subarray Sums Equal¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, greedy, sorting, number theory
2447. Number of Subarrays With GCD Equal to K¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, number theory
2543. Check if Point Is Reachable¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, number theory
2183. Count Array Pairs Divisible by K¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, math, number theory
3312. Sorted GCD Pair Queries¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, hash table, math, binary search, combinatorics, counting, number theory, prefix sum
1819. Number of Different Subsequences GCDs¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, math, counting, number theory
2436. Minimum Split Into Subarrays With GCD Greater Than One¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, dynamic programming, greedy, number theory
2464. Minimum Subarrays in a Valid Split¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, dynamic programming, number theory
2941. Maximum GCD-Sum of a Subarray¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, math, binary search, number theory