`s0`

and `s1`

, return the number of substrings where `s1`

contains any anagram of `s0`

.
**Constraints**

`n ≤ 100,000`

where`n`

is the length of`s0`

`m ≤ 100,000`

where`m`

is the length of`s1`

https://binarysearch.com/problems/Anagram-Substrings

**Input**

- s0 =
`abc`

- s1 =
`bcabxabc`

**Output**

- answer =
`3`

**Explanation**

The substrings `"bca"`

, `"cab"`

and `"abc"`

of `s0`

are permutations of `"abc"`

.

`n`

and a two-dimensional list of integers `enemies`

. Integer `n`

means there’s `n`

people labeled from `[0, n - 1]`

. Each element in `enemies`

contains `[person_a, person_b]`

which means that `person_a`

and `person_b`

are enemies.
Return whether it’s possible to partition the `n`

people into two groups such that no two people that are enemies are in the same group.

**Constraints**

`n ≤ 1,000`

`m ≤ 10,000`

where`m`

is the length of`enemies`

https://binarysearch.com/problems/Separate-People-Given-Dislike-Relations

**Input**

- n =
`4`

- enemies =

```
[[0,1],
[1,2]]
```

**Output**

- answer =
`True`

**Explanation**

We can have these two groups `[0, 2, 3]`

and `[1]`

.

**Input**

- n =
`3`

- enemies =

```
[[0,1],
[0,2],
[1,2]]
```

**Output**

- answer =
`False`

**Explanation**

No matter how we split the two groups, there will be two people that are enemies in a group.

`weights`

and `values`

which have the same length and an integer `capacity`

. `weights[i]`

and `values[i]`

represent the weight and value of the `i`

th item.
Given that you can take at most `capacity`

weights, and that you can take a fraction of an item’s weight with proportionate value, return the maximum amount of value you can get, rounded down to the nearest integer.

**Constraints**

`n ≤ 100,000`

where`n`

is the length of`weights`

and`values`

https://binarysearch.com/problems/Fractional-Knapsack

**Input**

- weights =
`[5, 6, 2]`

- values =
`[100, 100, 1]`

- capacity =
`8`

**Output**

- answer =
`150`

**Explanation**

The best we can do is:

- Take the item with
`5`

weight and take the`100`

value, leaving us with`3`

capacity - Take half of the item with
`6`

weight and take half of the`100`

value.

**Input**

- weights =
`[5, 6, 2]`

- values =
`[100, 100, 1]`

- capacity =
`13`

**Output**

- answer =
`201`

**Explanation**

We can take all `3`

items in full

`nums`

and an integer `diff`

, return the length of the longest arithmetic subsequence where the difference between each consecutive numbers in the subsequence is `diff`

.
**Constraints**

`0 ≤ n ≤ 100,000`

where`n`

is the length of`nums`

https://binarysearch.com/problems/Longest-Arithmetic-Subsequence-with-Difference-Constraint

**Input**

- nums =
`[-2, 0, 3, 6, 1, 9]`

- diff =
`3`

**Output**

- answer =
`4`

**Explanation**

We can pick the subsequence `[0, 3, 6, 9]`

.

**Input**

- nums =
`[9, 8, 7, 5, 3]`

- diff =
`-2`

**Output**

- answer =
`4`

**Explanation**

We can pick the subsequence `[9, 7, 5, 3]`

.

`matrix`

and an integer `k`

, return the largest sum of a rectangle `≤ k`

.
**Constraints**

`n, m ≤ 100`

where`n`

and`m`

are the number of rows and columns in`matrix`

.

https://binarysearch.com/problems/Maximum-Sum-Rectangle-with-Condition

**Input**

- matrix =

```
[[ 2,-2],
[ 3, 2]]
```

- k =
`6`

**Output**

- answer =
`5`

**Explanation**

We can take the rectangle `[2, 3]`

to get sum of `5`

.

`nums`

, rearrange its order to form the largest possible integer and return it as a string.
**Constraints**

`n ≤ 1,000`

where`n`

is the length of`nums`

`nums[i] ≤ 1,000`

https://binarysearch.com/problems/Create-Largest-Number-From-a-List

**Input**

- nums =
`[10, 7, 76, 415]`

**Output**

- answer =
`77641510`

**Input**

- nums =
`[961, 745, 331, 794, 923]`

**Output**

- answer =
`961923794745331`

**Input**

- nums =
`[45, 14, 70, 67, 95]`

**Output**

- answer =
`9570674514`

**Input**

- nums =
`[70, 5, 94, 18, 78]`

**Output**

- answer =
`947870518`

`nums`

, remove numbers that appear multiple times in the list, while maintaining order of the appearance in the original list.
It should use \(\mathcal{O}(k)\) space where `k`

is the number of unique integers.

**Constraints**

`n ≤ 100,000`

where`n`

is the length of`nums`

https://binarysearch.com/problems/Remove-Duplicate-Numbers

**Input**

- nums =
`[1, 3, 5, 0, 3, 5, 8]`

**Output**

- answer =
`[1, 0, 8]`

**Explanation**

Only [1, 0, 8] are unique in the list and that’s the order they appear in.

`matrix`

, find the length of the longest strictly increasing path. You can move up, down, left, or right.
**Constraints**

`n, m ≤ 500`

where`n`

and`m`

are the number of rows and columns in`matrix`

https://binarysearch.com/problems/Longest-Increasing-Path

**Input**

- matrix =

```
[[1,3,5],
[0,4,6],
[2,2,9]]
```

**Output**

- answer =
`6`

**Explanation**

The longest path is `[0, 1, 3, 5, 6, 9]`

`k`

and a list of integers `nums`

, return the length of the longest sublist that contains at most `k`

distinct integers.
**Constraints**

`0 ≤ k ≤ n ≤ 100,000`

where`n`

is the length of`nums`

https://binarysearch.com/problems/Longest-Sublist-with-K-Distinct-Numbers

**Input**

- k =
`1`

- nums =
`[0, 0, 0, 0, 0]`

**Output**

- answer =
`5`

**Input**

- k =
`2`

- nums =
`[0, 1, 2, 1, 0]`

**Output**

- answer =
`3`

**Explanation**

The longest substring with `2`

distinct integers is `[1,2,1]`

, which has length of `3`

.

**Input**

- k =
`1`

- nums =
`[0, 1, 2, 3, 4]`

**Output**

- answer =
`1`

`a`

and `b`

that are the same length. Partition them into substrings such that each pair of `a`

and `b`

’s substring is the same size and they are anagrams of each other. Return the cut indexes such that it results in the largest number of cuts of `a`

and `b`

. Return the empty list if no result exists.
**Constraints**

`n ≤ 100,000`

where`n`

is the length of`a`

and`b`

https://binarysearch.com/problems/Anagram-Partitioning

**Input**

- a =
`study`

- b =
`dusty`

**Output**

- answer =
`[0, 4]`

**Explanation**

We can cut the string into 2 partitions:

`a = ["stud", "y"]`

`b = ["dust", "y"]`

**Input**

- a =
`catdogwolf`

- b =
`actgodflow`

**Output**

- answer =
`[0, 2, 3, 6]`

**Explanation**

We can cut the string into 4 partitions such that each string is an anagram of each other.

`a = ["ca", "t", "dog", "wolf"]`

`b = ["ac", "t", "god", "flow"]`