```cpp
bool isReflected(vector<vector<int>>& points) {
    int minX = INT_MAX;
    int maxX = INT_MIN;

    unordered_set<string> pointSet;
    for(const auto& point : points) {
        minX = min(minX, point[0]);
        maxX = max(maxX, point[0]);
        pointSet.insert(to_string(point[0]) + "," + to_string(point[1]));
    }

    int sum = minX + maxX;
    for(const auto& point : points) {
        if(!pointSet.count(to_string(sum - point[0]) + "," + to_string(point[1]))) {
            return false;
        }
    }

    return true;
}
```

False True False False False False False False True False True False False False True False False True False True True True False True True True False False False True False False False False True False True True True True False True False False True

```python
def isReflected(points):
    min_x = min(point[0] for point in points)
    max_x = max(point[0] for point in points)
    point_set = {(point[0], point[1]) for point in points}

    sum_x = min_x + max_x
    for point in points:
        if (sum_x - point[0], point[1]) not in point_set:
            return False

    return True
```


```java
public int countNumbersWithUniqueDigits(int n) {
    if (n == 0) return 1;

    int total = 10;
    int uniqueDigits = 9;
    int currentAvailableDigits = 9;

    while (n-- > 1 && currentAvailableDigits > 0) {
        uniqueDigits *= currentAvailableDigits;
        total += uniqueDigits;
        currentAvailableDigits--;
    }

    return total;
}
```

```cpp
int countNumbersWithUniqueDigits(int n) {
    if (n == 0) return 1;

    int total = 10;
    int uniqueDigits = 9;
    int currentAvailableDigits = 9;

    while(n-- > 1 && currentAvailableDigits > 0) {
        uniqueDigits *= currentAvailableDigits;
        total += uniqueDigits;
        currentAvailableDigits--;
    }

    return total;
}
```


```cpp
#include <queue>
#include <unordered_map>
#include <string>
using namespace std;

string rearrangeString(string s, int k) {
    if (k == 0) return s;

    unordered_map<char, int> freq;
    for (char c : s) {
        freq[c]++;
    }

    priority_queue<pair<int, char>> max_heap;
    for (const auto& kv : freq) {
        max_heap.emplace(kv.second, kv.first);
    }

    string result;
    while (!max_heap.empty()) {
        vector<pair<int, char>> temp;

        for (int i = 0; i < k && !max_heap.empty(); ++i) {
            auto curr = max_heap.top();
            max_heap.pop();

            result += curr.second;
            if (--curr.first > 0) {
                temp.push_back(curr);
            }
        }

        for (const auto& entry : temp) {
            max_heap.push(entry);
        }

        if (max_heap.empty()) break;
        if (result.length() < s.length()) result.append(k - temp.size(), ' ');
    }

    if (result.length() < s.length()) return "";
    return result;
}
```

a bc
abacab  c
abc             abc
abc   abc
abcdefg
abc        abc
abc                         abc
abc  abc
abc     abc
c ab   c
abc                   abc
abc ab   c
abc              abc
abcd a  bcd
abc       abc
abcabc
abc    abc
abc                        abc
abc           abc
a  a
ab ab ab
c  abc
abc                  abc
abc ab ab
a  bc
abc ab   c
ab   c
abc  abc
abc               abc
abc  abc
abc abc
abc                abc
abc         abc
a b  aca
c a  bc
abc                    abc
xyzxyzxy  z
a  bcde
abc                       abc
a  a
abac a  bcd
abc ab   c
abc                     abc
ab a  b
abc            abc
abc                 abc
abc      abc
abc                      abc
abc          abc
abcdefabc   def

```python
import heapq
from collections import Counter

def rearrange_string(s, k):
    if k == 0:
        return s

    counter = Counter(s)
    max_heap = [(-count, char) for char, count in counter.items()]
    heapq.heapify(max_heap)

    result = []
    while max_heap:
        temp = []

        for _ in range(k):
            if not max_heap:
                break

            count, char = heapq.heappop(max_heap)
            result.append(char)

            if count + 1 < 0:
                temp.append((count + 1, char))

        for item in temp:
            heapq.heappush(max_heap, item)

        if not max_heap:
            break

        if len(result) < len(s):
            result.extend([' '] * (k - len(temp)))

    if len(result) < len(s):
        return ""
    return "".join(result)
```


```cpp
vector<int> sortTransformedArray(vector<int>& nums, int a, int b, int c) {
    vector<int> result(nums.size());
    int i = 0, j = nums.size() - 1, index = (a >= 0) ? nums.size() - 1 : 0;

    while (i <= j) {
        int left = nums[i] * nums[i] * a + nums[i] * b + c;
        int right = nums[j] * nums[j] * a + nums[j] * b + c;

        if (a >= 0) {
            if (left >= right) {
                result[index--] = left;
                i++;
            } else {
                result[index--] = right;
                j--;
            }
        } else {
            if (left <= right) {
                result[index++] = left;
                i++;
            } else {
                result[index++] = right;
                j--;
            }
        }
    }
    return result;
}
```

```python
def sort_transformed_array(nums, a, b, c):
    result = [0] * len(nums)
    i, j = 0, len(nums) - 1
    index = len(nums) - 1 if a >= 0 else 0

    while i <= j:
        left = nums[i] * nums[i] * a + nums[i] * b + c
        right = nums[j] * nums[j] * a + nums[j] * b + c

        if a >= 0:
            if left >= right:
                result[index] = left
                index -= 1
                i += 1
            else:
                result[index] = right
                index -= 1
                j -= 1
        else:
            if left <= right:
                result[index] = left
                index += 1
                i += 1
            else:
                result[index] = right
                index += 1
                j -= 1
    return result
```


```cpp
int maxKilledEnemies(vector<vector<char>>& grid) {
    if (grid.empty()) return 0;
    int m = grid.size(), n = grid[0].size(), result = 0, rowhits = 0;
    vector<int> colhits(n, 0);
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (j == 0 || grid[i][j - 1] == 'W') {
                rowhits = 0;
                for (int k = j; k < n && grid[i][k] != 'W'; k++)
                    rowhits += grid[i][k] == 'E';
            }
            if (i == 0 || grid[i - 1][j] == 'W') {
                colhits[j] = 0;
                for (int k = i; k < m && grid[k][j] != 'W'; k++)
                    colhits[j] += grid[k][j] == 'E';
            }
            if (grid[i][j] == '0') result = max(result, rowhits + colhits[j]);
        }
    }
    return result;
}
```

```python
def maxKilledEnemies(grid):
    if not grid: return 0
    m, n, result, rowhits = len(grid), len(grid[0]), 0, 0
    colhits = [0] * n
    for i in range(m):
        for j in range(n):
            if j == 0 or grid[i][j - 1] == 'W':
                rowhits = 0
                k = j
                while k < n and grid[i][k] != 'W':
                    rowhits += grid[i][k] == 'E'
                    k += 1
            if i == 0 or grid[i - 1][j] == 'W':
                colhits[j] = 0
                k = i
                while k < m and grid[k][j] != 'W':
                    colhits[j] += grid[k][j] == 'E'
                    k += 1
            if grid[i][j] == '0':
                result = max(result, rowhits + colhits[j])
    return result
```


```cpp
bool canMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity) {
    if (targetCapacity > jug1Capacity + jug2Capacity) return false;
    if (jug1Capacity == targetCapacity || jug2Capacity == targetCapacity
        || jug1Capacity + jug2Capacity == targetCapacity) return true;
    return targetCapacity % gcd(jug1Capacity, jug2Capacity) == 0;
}

int gcd(int a, int b) {
    while (b) {
        int tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}
```

jug1Capacity = 3, jug2Capacity = 5, targetCapacity = 4

true true true true true true true true true true true true true true true true true true true true true true true true true true true true true true true true true true true true true true true true true

```java
public boolean canMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity) {
    if (targetCapacity > jug1Capacity + jug2Capacity) return false;
    if (jug1Capacity == targetCapacity || jug2Capacity == targetCapacity
        || jug1Capacity + jug2Capacity == targetCapacity) return true;
    return targetCapacity % gcd(jug1Capacity, jug2Capacity) == 0;
}

private int gcd(int a, int b) {
    while (b != 0) {
        int tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}
```


```cpp
#include <vector>

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

void findLeaves(TreeNode* node, std::vector<std::vector<int>>& result, int& level) {
    if (!node) return;
    if (!node->left && !node->right) {
        if (result.size() <= level) {
            result.push_back(std::vector<int>());
        }
        result[level].push_back(node->val);
        node = nullptr;
        return;
    }
    level++;
    findLeaves(node->left, result, level);
    findLeaves(node->right, result, level);
    level--;
}

std::vector<std::vector<int>> findLeaves(TreeNode* root) {
    std::vector<std::vector<int>> result;
    int level = 0;
    while (root) {
        findLeaves(root, result, level);
        if (!root->left && !root->right) root = nullptr;
    }
    return result;
}
```

```python
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def find_leaves(node, result, level):
    if not node:
        return -1
    left_level = find_leaves(node.left, result, level + 1)
    right_level = find_leaves(node.right, result, level + 1)
    level = max(left_level, right_level) + 1
    if len(result) <= level:
        result.append([])
    result[level].append(node.val)
    return level

def findLeaves(root):
    result = []
    find_leaves(root, result, 0)
    return result
```


```java
import java.util.*;

public List<Integer> largestDivisibleSubset(int[] nums) {
    Arrays.sort(nums);
    int n = nums.length;
    int[] count = new int[n];
    int[] prev = new int[n];
    int max_idx = 0;
    Arrays.fill(prev, -1);
    Arrays.fill(count, 1);

    for (int i = 1; i < n; i++) {
        for (int j = 0; j < i; j++) {
            if (nums[i] % nums[j] == 0 && count[i] < count[j] + 1) {
                count[i] = count[j] + 1;
                prev[i] = j;
            }
        }
        if (count[max_idx] < count[i]) max_idx = i;
    }

    List<Integer> res = new ArrayList<>();
    for (int i = max_idx; i >= 0; i = prev[i]) {
        res.add(nums[i]);
    }

    return res;
}
```

```cpp
#include <vector>
#include <algorithm>
using namespace std;

vector<int> largestDivisibleSubset(vector<int>& nums) {
    sort(nums.begin(), nums.end());
    int n = nums.size();
    vector<int> count(n, 1), prev(n, -1), res;
    int max_idx = 0;

    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            if (nums[i] % nums[j] == 0 && count[i] < count[j] + 1) {
                count[i] = count[j] + 1;
                prev[i] = j;
            }
        }
        if (count[max_idx] < count[i]) max_idx = i;
    }

    for (int i = max_idx; i >= 0; i = prev[i]) {
        res.push_back(nums[i]);
    }

    return res;
}
```


```java
public class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}

public ListNode plusOne(ListNode head) {
    if (head == null) return head;
    int carry = plusOneDfs(head);
    if (carry == 1) {
        ListNode newHead = new ListNode(1);
        newHead.next = head;
        return newHead;
    }
    return head;
}

private int plusOneDfs(ListNode node) {
    if (node == null) return 1;
    int carry = plusOneDfs(node.next);
    if (carry + node.val == 10) {
        node.val = 0;
        return 1;
    } else {
        node.val += carry;
        return 0;
    }
}
```

```cpp
struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

ListNode* plusOne(ListNode* head) {
    if (head == NULL) return head;
    if (plusOneDfs(head) == 1) {
        ListNode* newHead = new ListNode(1);
        newHead->next = head;
        return newHead;
    }
    return head;
}

int plusOneDfs(ListNode* node) {
    if (node == NULL) return 1;
    int carry = plusOneDfs(node->next);
    if (carry + node->val == 10) {
        node->val = 0;
        return 1;
    } else {
        node->val += carry;
        return 0;
    }
}
```


```java
public int add(int a, int b) {
    while (b != 0) {
        int carry = a & b;
        a = a ^ b;
        b = carry << 1;
    }
    return a;
}
```

```python
def add(a, b):
    MAX = 0x7FFFFFFF
    MASK = 0xFFFFFFFF
    while b:
        a, b = (a ^ b) & MASK, ((a & b) << 1) & MASK
    return a if a <= MAX else ~(a ^ MASK)
```


```cpp
vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {
    auto comp = [&nums1, &nums2](pair<int, int> a, pair<int, int> b) {
        return nums1[a.first] + nums2[a.second] > nums1[b.first] + nums2[b.second];
    };
    priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(comp)> min_heap(comp);
    vector<vector<int>> result;

    if (nums1.empty() || nums2.empty()) return result;

    for (int i = 0; i < nums1.size(); ++i) {
        min_heap.emplace(i, 0);
    }

    while (k-- && !min_heap.empty()) {
        auto curr = min_heap.top();
        min_heap.pop();
        result.push_back({nums1[curr.first], nums2[curr.second]});
        if (curr.second + 1 < nums2.size()) {
            min_heap.emplace(curr.first, curr.second + 1);
        }
    }
    return result;
}
```

```python
import heapq

def kSmallestPairs(nums1, nums2, k):
    if not nums1 or not nums2:
        return []

    heap = [(nums1[i] + nums2[0], i, 0) for i in range(min(k, len(nums1)))]
    heapq.heapify(heap)
    result = []

    while k > 0 and heap:
        s, i, j = heapq.heappop(heap)
        result.append([nums1[i], nums2[j]])
        if j + 1 < len(nums2):
            heapq.heappush(heap, (nums1[i] + nums2[j + 1], i, j + 1))
        k -= 1

    return result
```


```java
public int getMoneyAmount(int n) {
    int[][] dp = new int[n + 1][n + 1];
    for (int i = n - 1; i >= 1; i--) {
        for (int j = i + 1; j <= n; j++) {
            int min_cost = Integer.MAX_VALUE;
            for (int k = i; k < j; k++) {
                int cost = k + Math.max(dp[i][k - 1], dp[k + 1][j]);
                min_cost = Math.min(min_cost, cost);
            }
            dp[i][j] = min_cost;
        }
    }
    return dp[1][n];
}
```

```cpp
int getMoneyAmount(int n) {
    vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
    for (int i = n - 1; i >= 1; i--) {
        for (int j = i + 1; j <= n; j++) {
            int min_cost = INT_MAX;
            for (int k = i; k < j; k++) {
                int cost = k + max(dp[i][k - 1], dp[k + 1][j]);
                min_cost = min(min_cost, cost);
            }
            dp[i][j] = min_cost;
        }
    }
    return dp[1][n];
}
```


```python
def wiggleMaxLength(nums):
    if len(nums) < 2:
        return len(nums)

    up, down = 1, 1
    for i in range(1, len(nums)):
        if nums[i] > nums[i - 1]:
            up = down + 1
        elif nums[i] < nums[i - 1]:
            down = up + 1
    return max(up, down)
```

```cpp
int wiggleMaxLength(vector<int>& nums) {
    int len = nums.size();
    if (len < 2) return len;

    int up = 1, down = 1;
    for (int i = 1; i < len; ++i) {
        if (nums[i] > nums[i - 1])
            up = down + 1;
        else if (nums[i] < nums[i - 1])
            down = up + 1;
    }
    return max(up, down);
}
```


```java
public int combinationSum(int[] nums, int target) {
    int[] dp = new int[target + 1];
    dp[0] = 1;

    for(int num : nums) {
        for(int i = num; i <= target; i++) {
            dp[i] += dp[i - num];
        }
    }

    return dp[target];
}
```

```cpp
#include <vector>
using namespace std;

int combinationSum(vector<int>& nums, int target) {
    vector<int> dp(target + 1, 0);
    dp[0] = 1;

    for(int num : nums) {
        for(int i = num; i <= target; i++) {
            dp[i] += dp[i - num];
        }
    }

    return dp[target];
}
```


```python
import heapq

def kthSmallest(matrix, k):
    n = len(matrix)
    min_heap = []

    for i in range(n):
        heapq.heappush(min_heap, (matrix[i][0], i, 0))

    while k > 1:
        val, row, col = heapq.heappop(min_heap)

        if col + 1 < n:
            heapq.heappush(min_heap, (matrix[row][col + 1], row, col + 1))

        k -= 1

    return min_heap[0][0]
```

```cpp
#include <queue>
#include <vector>

int kthSmallest(std::vector<std::vector<int>>& matrix, int k) {
    int n = matrix.size();
    std::priority_queue<std::pair<int, std::pair<int, int>>, std::vector<std::pair<int, std::pair<int, int>>>, std::greater<>> min_heap;

    for (int i = 0; i < n; ++i) {
        min_heap.emplace(matrix[i][0], std::make_pair(i, 0));
    }

    while (--k) {
        auto [val, pos] = min_heap.top();
        min_heap.pop();

        if (++pos.second < n) {
            min_heap.emplace(matrix[pos.first][pos.second], pos);
        }
    }

    return min_heap.top().first;
}
```


```cpp
#include <string>
#include <unordered_map>

bool canConstruct(std::string ransomNote, std::string magazine) {
    std::unordered_map<char, int> letterCount;
    for (char c : magazine) {
        letterCount[c]++;
    }

    for (char c : ransomNote) {
        if (letterCount[c] == 0) {
            return false;
        }
        letterCount[c]--;
    }

    return true;
}
```

False False False False True True False False False True True False True False True False True True False True False False False False False False True True True False False False True True False True True False True False False True True False True

```python
def can_construct(ransom_note, magazine):
    letter_count = {}

    for c in magazine:
        letter_count[c] = letter_count.get(c, 0) + 1

    for c in ransom_note:
        if c not in letter_count or letter_count[c] == 0:
            return False
        letter_count[c] -= 1

    return True
```


```cpp
int firstUniqChar(std::string s) {
    std::unordered_map<char, int> charCount;
    for (char c : s)
        charCount[c]++;
    for (int i = 0; i < s.length(); i++)
        if (charCount[s[i]] == 1)
            return i;
    return -1;
}
```

aeeeddbbd abcabcabc aeeeddbce aeeeddbbt aeeeddbby aeeeddbcc aeeeddbbv a aeeeddbbh loveleetcode aeeeddbch aeeeddbbe aabb ab aeeeddbbo abaccdeff aeeeddbbc aeeeddbbs ba aeeeddbbf aaac cbd aeeeddbbw aabbccddeeffg aeeeddbcd aeeeddbbk aeeeddbbb aeeeddbbj aeeeddbbm leetcode aeeeddbbp aeeeddbbi aeeeddbcb aeeeddbbz cdab LEVeldom aeeeddbbg aeeeddbbx aeeeddbcg aeeeddbcj aeeeddbcf ac abcd aabbccddeeffgg acdb aeeeddbbr aeeeddbbu baa zaz aeeeddba aeeeddbbq aeeeddbca aeeeddbci leetcode abab aeeeddbbn aeeeddbbl

```java
public int firstUniqChar(String s) {
    HashMap<Character, Integer> charCount = new HashMap<>();
    for (char c : s.toCharArray())
        charCount.put(c, charCount.getOrDefault(c, 0) + 1);
    for (int i = 0; i < s.length(); i++)
        if (charCount.get(s.charAt(i)) == 1)
            return i;
    return -1;
}
```


```cpp
char findTheDifference(std::string s, std::string t) {
    int sum_s = 0, sum_t = 0;
    for(char c : s) sum_s += c;
    for(char c : t) sum_t += c;
    return sum_t - sum_s;
}
```

d a w m b r k o j x y q a n u c a h z e E f l y q ô z s i i e u b l e g v a p t z

```python
def findTheDifference(s: str, t: str) -> str:
    return chr(sum(ord(c) for c in t) - sum(ord(c) for c in s))
```


```python
def last_remaining(n: int) -> int:
    direction = True
    head = 1
    remaining = n
    step = 1

    while remaining > 1:
        if direction or remaining % 2 == 1:
            head += step
        remaining //= 2
        step *= 2
        direction = not direction

    return head
```

```cpp
int lastRemaining(int n) {
    bool direction = true;
    int head = 1, remaining = n, step = 1;

    while (remaining > 1) {
        if (direction || remaining % 2 == 1) {
            head += step;
        }
        remaining /= 2;
        step *= 2;
        direction = !direction;
    }

    return head;
}
```


```java
public boolean validUtf8(int[] data) {
    int count = 0;
    for (int byteValue : data) {
        if (count == 0) {
            if ((byteValue >> 5) == 0b110) count = 1;
            else if ((byteValue >> 4) == 0b1110) count = 2;
            else if ((byteValue >> 3) == 0b11110) count = 3;
            else if ((byteValue >> 7) == 1) return false;
        } else {
            if ((byteValue >> 6) != 0b10) return false;
            count--;
        }
    }
    return count == 0;
}
```

true false true true true true false false false false false true true true true true true true false false true true true true false true true true false

```cpp
bool validUtf8(vector<int>& data) {
    int count = 0;
    for (int byte : data) {
        if (count == 0) {
            if ((byte >> 5) == 0b110) count = 1;
            else if ((byte >> 4) == 0b1110) count = 2;
            else if ((byte >> 3) == 0b11110) count = 3;
            else if ((byte >> 7)) return false;
        } else {
            if ((byte >> 6) != 0b10) return false;
            count--;
        }
    }
    return count == 0;
}
```


```cpp
#include <string>
#include <stack>

std::string decodeString(const std::string &s) {
    std::stack<int> counts;
    std::stack<std::string> results;
    std::string current;
    int ptr = 0;

    while (ptr < s.size()) {
        if (isdigit(s[ptr])) {
            int count = 0;
            while (isdigit(s[ptr])) {
                count = count * 10 + (s[ptr] - '0');
                ptr++;
            }
            counts.push(count);
        } else if (s[ptr] == '[') {
            results.push(current);
            current = "";
            ptr++;
        } else if (s[ptr] == ']') {
            std::string prev = results.top();
            results.pop();
            int count = counts.top();
            counts.pop();
            for (int i = 0; i < count; i++) {
                prev += current;
            }
            current = prev;
            ptr++;
        } else {
            current += s[ptr];
            ptr++;
        }
    }

    return current;
}
```

```python
def decodeString(s):
    counts = []
    results = []
    current = ""
    ptr = 0

    while ptr < len(s):
        if s[ptr].isdigit():
            count = 0
            while s[ptr].isdigit():
                count = count * 10 + int(s[ptr])
                ptr += 1
            counts.append(count)
        elif s[ptr] == '[':
            results.append(current)
            current = ""
            ptr += 1
        elif s[ptr] == ']':
            prev = results.pop()
            count = counts.pop()
            current = prev + current * count
            ptr += 1
        else:
            current += s[ptr]
            ptr += 1

    return current
```


```cpp
#include <string>
#include <unordered_map>
#include <algorithm>

int longestSubstring(const std::string& s, int k) {
    if (s.empty() || k <= 0) return 0;

    std::unordered_map<char, int> char_count;
    for (char ch : s)
        char_count[ch]++;

    for (const auto& item : char_count) {
        if (item.second < k) {
            int res = 0;
            for (const std::string& str : split(s, item.first))
                res = std::max(res, longestSubstring(str, k));
            return res;
        }
    }
    return s.length();
}

std::vector<std::string> split(const std::string& s, char delimiter) {
    std::vector<std::string> subs;
    size_t start = 0;
    size_t end = s.find(delimiter);
    while (end != std::string::npos) {
        subs.push_back(s.substr(start, end - start));
        start = end + 1;
        end = s.find(delimiter, start);
    }
    subs.push_back(s.substr(start));
    return subs;
}
```

```java
import java.util.*;

public int longestSubstring(String s, int k) {
    if (s == null || s.length() == 0 || k <= 0) return 0;

    Map<Character, Integer> charCount = new HashMap<>();
    for (char ch : s.toCharArray())
        charCount.put(ch, charCount.getOrDefault(ch, 0) + 1);

    for (Map.Entry<Character, Integer> entry : charCount.entrySet()) {
        if (entry.getValue() < k) {
            int res = 0;
            for (String str : s.split(Character.toString(entry.getKey())))
                res = Math.max(res, longestSubstring(str, k));
            return res;
        }
    }
    return s.length();
}
```


```cpp
int maxRotateFunction(vector<int>& nums) {
    int n = nums.size();
    int total_sum = 0;
    int f = 0;

    for (int i = 0; i < n; i++) {
        total_sum += nums[i];
        f += i * nums[i];
    }

    int max_f = f;
    for (int i = 1; i < n; i++) {
        f += total_sum - n * nums[n - i];
        max_f = max(max_f, f);
    }

    return max_f;
}
```

```python
def maxRotateFunction(nums):
    n = len(nums)
    total_sum = sum(nums)
    f = sum(i * num for i, num in enumerate(nums))

    max_f = f
    for i in range(1, n):
        f += total_sum - n * nums[-i]
        max_f = max(max_f, f)

    return max_f
```


```python
def min_operations(n):
    steps = 0
    while n > 1:
        n = n // 2 if n % 2 == 0 else n - 1
        steps += 1
    return steps
```

```java
int minOperations(int n) {
    int steps = 0;
    while(n > 1) {
        n = (n % 2 == 0) ? n / 2 : n - 1;
        steps++;
    }
    return steps;
}
```


```java
public int findNthDigit(int n) {
    int size = 1;
    long length = 9;
    int start = 1;

    while (n > length * size) {
        n -= length * size;
        size++;
        length *= 10;
        start *= 10;
    }

    start += (n - 1) / size;
    String s = Integer.toString(start);
    return Character.getNumericValue(s.charAt((n - 1) % size));
}
```

```cpp
int findNthDigit(int n) {
    int size = 1;
    long length = 9;
    int start = 1;

    while (n > length * size) {
        n -= length * size;
        size++;
        length *= 10;
        start *= 10;
    }

    start += (n - 1) / size;
    string s = to_string(start);
    return s[(n - 1) % size] - '0';
}
```


```python
def readBinaryWatch(turnedOn: int):
    def count_bits(n):
        return bin(n).count('1')

    times = []
    for h in range(12):
        for m in range(60):
            if count_bits(h) + count_bits(m) == turnedOn:
                times.append(f"{h}:{m:02d}")
    return times
```

```cpp
#include <vector>
#include <string>
using namespace std;

vector<string> readBinaryWatch(int turnedOn) {
    vector<string> times;
    for (int h = 0; h < 12; h++) {
        for (int m = 0; m < 60; m++) {
            if (__builtin_popcount(h) + __builtin_popcount(m) == turnedOn) {
                times.push_back(to_string(h) + (m < 10 ? ":0" : ":") + to_string(m));
            }
        }
    }
    return times;
}
```


```java
public String removeKDigits(String num, int k) {
    StringBuilder result = new StringBuilder();
    for (char c : num.toCharArray()) {
        while (k > 0 && result.length() > 0 && result.charAt(result.length() - 1) > c) {
            result.setLength(result.length() - 1);
            k--;
        }
        result.append(c);
    }
    result.setLength(result.length() - k);
    while (result.length() > 0 && result.charAt(0) == '0') {
        result.deleteCharAt(0);
    }
    return result.length() == 0 ? "0" : result.toString();
}
```

```python
def remove_k_digits(num, k):
    stack = []
    for c in num:
        while k > 0 and stack and stack[-1] > c:
            stack.pop()
            k -= 1
        stack.append(c)
    while k > 0:
        stack.pop()
        k -= 1
    return ''.join(stack).lstrip('0') or '0'
```


```python
def can_cross(stones):
    dp = {stone: set() for stone in stones}
    dp[0].add(0)

    for stone in stones:
        for k in dp[stone]:
            for jump in (k - 1, k, k + 1):
                if jump > 0 and stone + jump in dp:
                    dp[stone + jump].add(jump)

    return bool(dp[stones[-1]])
```

false true true false false false false false false false true false true false false false false false false false false false false true false true

```cpp
#include <unordered_map>
#include <vector>
using namespace std;

bool canCross(vector<int>& stones) {
    unordered_map<int, unordered_set<int>> dp;
    int n = stones.size();
    for (int stone : stones)
        dp[stone] = unordered_set<int>();
    dp[0].insert(0);

    for (int stone : stones) {
        for (int k : dp[stone]) {
            for (int jump : {k - 1, k, k + 1}) {
                if (jump > 0 && dp.count(stone + jump))
                    dp[stone + jump].insert(jump);
            }
        }
    }
    return !dp[stones.back()].empty();
}
```


```cpp
struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

int sumOfLeftLeaves(TreeNode* root) {
    if (!root) return 0;
    int sum = 0;
    if (root->left && !root->left->left && !root->left->right) sum += root->left->val;
    return sum + sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right);
}
```

```python
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def sum_of_left_leaves(root):
    if not root:
        return 0
    left_sum = 0
    if root.left and not root.left.left and not root.left.right:
        left_sum += root.left.val
    return left_sum + sum_of_left_leaves(root.left) + sum_of_left_leaves(root.right)
```


```java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public int[][] reconstructQueue(int[][] people) {
    Arrays.sort(people, (a, b) -> a[0] == b[0] ? a[1] - b[1] : b[0] - a[0]);

    List<int[]> result = new ArrayList<>();
    for (int[] p : people) {
        result.add(p[1], p);
    }
    return result.toArray(new int[people.length][2]);
}
```

```cpp
#include <vector>
#include <algorithm>

std::vector<std::vector<int>> reconstructQueue(std::vector<std::vector<int>>& people) {
    std::sort(people.begin(), people.end(), [](const std::vector<int>& a, const std::vector<int>& b) {
        return a[0] > b[0] || (a[0] == b[0] && a[1] < b[1]);
    });

    std::vector<std::vector<int>> result;
    for (const std::vector<int>& p : people) {
        result.insert(result.begin() + p[1], p);
    }
    return result;
}
```


```python
import heapq

def trapRainWater(heightMap):
    m, n = len(heightMap), len(heightMap[0])
    pq = []
    visited = [[False] * n for _ in range(m)]

    for i in range(m):
        heapq.heappush(pq, (heightMap[i][0], i, 0))
        heapq.heappush(pq, (heightMap[i][n - 1], i, n - 1))
        visited[i][0] = visited[i][n - 1] = True

    for i in range(1, n - 1):
        heapq.heappush(pq, (heightMap[0][i], 0, i))
        heapq.heappush(pq, (heightMap[m - 1][i], m - 1, i))
        visited[0][i] = visited[m - 1][i] = True

    water, maxHeight = 0, 0
    dirs = ((0, 1), (0, -1), (1, 0), (-1, 0))

    while pq:
        h, r, c = heapq.heappop(pq)
        maxHeight = max(maxHeight, h)
        for dx, dy in dirs:
            x, y = r + dx, c + dy
            if x < 0 or x >= m or y < 0 or y >= n or visited[x][y]:
                continue
            if heightMap[x][y] < maxHeight:
                water += maxHeight - heightMap[x][y]
            heapq.heappush(pq, (heightMap[x][y], x, y))
            visited[x][y] = True

    return water
```

```cpp
#include <queue>
#include <vector>

using namespace std;

int trapRainWater(vector<vector<int>>& heightMap) {
    int m = heightMap.size(), n = heightMap[0].size();
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    vector<vector<int>> visited(m, vector<int>(n, 0));

    for (int i = 0; i < m; i++) {
        pq.push({heightMap[i][0], i * n});
        pq.push({heightMap[i][n - 1], i * n + n - 1});
        visited[i][0] = visited[i][n - 1] = 1;
    }

    for (int i = 1; i < n - 1; i++) {
        pq.push({heightMap[0][i], i});
        pq.push({heightMap[m - 1][i], (m - 1) * n + i});
        visited[0][i] = visited[m - 1][i] = 1;
    }

    int water = 0, maxHeight = 0;
    vector<vector<int>> dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

    while (!pq.empty()) {
        auto t = pq.top(); pq.pop();
        int h = t.first, r = t.second / n, c = t.second % n;
        maxHeight = max(maxHeight, h);
        for (auto dir : dirs) {
            int x = r + dir[0], y = c + dir[1];
            if (x < 0 || x >= m || y < 0 || y >= n || visited[x][y]) continue;
            if (heightMap[x][y] < maxHeight) water += maxHeight - heightMap[x][y];
            pq.push({heightMap[x][y], x * n + y});
            visited[x][y] = 1;
        }
    }

    return water;
}
```


```cpp
bool validWordAbbreviation(string word, string abbr) {
    int i = 0, j = 0;
    while (i < word.size() && j < abbr.size()) {
        if (isdigit(abbr[j])) {
            if (abbr[j] == '0') return false; // leading zero
            int num = 0;
            while (j < abbr.size() && isdigit(abbr[j]))
                num = num * 10 + (abbr[j++] - '0');
            i += num;
        } else {
            if (word[i++] != abbr[j++]) return false;
        }
    }
    return i == word.size() && j == abbr.size();
}
```

word =  "internationalization ", abbr =  "i12iz4n "

true false true false true false true false false true false true true true true false false false false true false true true false false true false true false true false false true false false true true false false true true true

```java
public boolean validWordAbbreviation(String word, String abbr) {
    int i = 0, j = 0;
    while (i < word.length() && j < abbr.length()) {
        if (Character.isDigit(abbr.charAt(j))) {
            if (abbr.charAt(j) == '0') return false; // leading zero
            int num = 0;
            while (j < abbr.length() && Character.isDigit(abbr.charAt(j)))
                num = num * 10 + (abbr.charAt(j++) - '0');
            i += num;
        } else {
            if (word.charAt(i++) != abbr.charAt(j++)) return false;
        }
    }
    return i == word.length() && j == abbr.length();
}
```


```cpp
int splitArray(vector<int>& nums, int m) {
    long long left = 0, right = 0;
    for (int num : nums) {
        left = max(left, (long long)num);
        right += num;
    }

    while (left < right) {
        long long mid = (left + right) / 2;
        int count = 1;
        long long curSum = 0;
        for (int num : nums) {
            curSum += num;
            if (curSum > mid) {
                curSum = num;
                count++;
            }
        }

        if (count > m) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }

    return (int)left;
}
```

```java
public int splitArray(int[] nums, int m) {
    long left = 0, right = 0;
    for (int num : nums) {
        left = Math.max(left, num);
        right += num;
    }

    while (left < right) {
        long mid = (left + right) / 2;
        int count = 1;
        long curSum = 0;
        for (int num : nums) {
            curSum += num;
            if (curSum > mid) {
                curSum = num;
                count++;
            }
        }

        if (count > m) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }

    return (int)left;
}
```


```python
def fizzBuzz(n):
    result = []
    for i in range(1, n + 1):
        if i % 15 == 0:
            result.append("FizzBuzz")
        elif i % 3 == 0:
            result.append("Fizz")
        elif i % 5 == 0:
            result.append("Buzz")
        else:
            result.append(str(i))
    return result
```

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94, Buzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94, Buzz, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94, Buzz, Fizz, 97]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94, Buzz, Fizz, 97, 98, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz]

[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94, Buzz, Fizz, 97, 98, Fizz, Buzz]

```java
import java.util.ArrayList;

public ArrayList<String> fizzBuzz(int n) {
    ArrayList<String> result = new ArrayList<>();
    for (int i = 1; i <= n; i++) {
        if (i % 15 == 0) result.add("FizzBuzz");
        else if (i % 3 == 0) result.add("Fizz");
        else if (i % 5 == 0) result.add("Buzz");
        else result.add(Integer.toString(i));
    }
    return result;
}
```


```python
def numberOfArithmeticSlices(nums):
    n = len(nums)
    count, cur = 0, 0
    for i in range(2, n):
        if nums[i] - nums[i - 1] == nums[i - 1] - nums[i - 2]:
            cur += 1
            count += cur
        else:
            cur = 0
    return count
```

```java
public int numberOfArithmeticSlices(int[] nums) {
    int n = nums.length, count = 0, cur = 0;
    for (int i = 2; i < n; ++i) {
        if (nums[i] - nums[i - 1] == nums[i - 1] - nums[i - 2]) {
            cur++;
            count += cur;
        } else {
            cur = 0;
        }
    }
    return count;
}
```


```java
import java.util.TreeSet;

public int thirdMax(int[] nums) {
    TreeSet<Integer> top3 = new TreeSet<>();
    for (int num : nums) {
        top3.add(num);
        if (top3.size() > 3) {
            top3.remove(top3.first());
        }
    }
    return top3.size() == 3 ? top3.first() : top3.last();
}
```

```python
def third_max(nums):
    top3 = set()
    for num in nums:
        top3.add(num)
        if len(top3) > 3:
            top3.remove(min(top3))
    return min(top3) if len(top3) == 3 else max(top3)
```


```cpp
#include <vector>
using namespace std;

bool canPartition(vector<int>& nums) {
    int sum = 0;
    for (int num : nums) sum += num;

    if (sum % 2 != 0) return false;

    int target = sum / 2;
    vector<bool> dp(target + 1, false);
    dp[0] = true;

    for (int num : nums) {
        for (int i = target; i >= num; i--) {
            dp[i] = dp[i] || dp[i - num];
        }
    }
    return dp[target];
}
```

false true false false false true false true false true false true false false true false false true false false false true true false false

```java
public boolean canPartition(int[] nums) {
    int sum = 0;
    for (int num : nums) sum += num;

    if (sum % 2 != 0) return false;

    int target = sum / 2;
    boolean[] dp = new boolean[target + 1];
    dp[0] = true;

    for (int num : nums) {
        for (int i = target; i >= num; i--) {
            dp[i] = dp[i] || dp[i - num];
        }
    }
    return dp[target];
}
```


```cpp
#include <vector>

using namespace std;

void dfs(const vector<vector<int>>& heights, int r, int c, int prevHeight, vector<vector<bool>>& visited) {
    if (r < 0 || r >= heights.size() || c < 0 || c >= heights[0].size())
        return;
    if (heights[r][c] >= prevHeight && !visited[r][c]) {
        visited[r][c] = true;
        dfs(heights, r - 1, c, heights[r][c], visited);
        dfs(heights, r + 1, c, heights[r][c], visited);
        dfs(heights, r, c - 1, heights[r][c], visited);
        dfs(heights, r, c + 1, heights[r][c], visited);
    }
}

vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {
    int m = heights.size();
    int n = heights[0].size();
    vector<vector<bool>> pacific(m, vector<bool>(n, false));
    vector<vector<bool>> atlantic(m, vector<bool>(n, false));

    for (int r = 0; r < m; ++r) {
        dfs(heights, r, 0, -1, pacific);
        dfs(heights, r, n - 1, -1, atlantic);
    }
    for (int c = 0; c < n; ++c) {
        dfs(heights, 0, c, -1, pacific);
        dfs(heights, m - 1, c, -1, atlantic);
    }
    vector<vector<int>> result;
    for (int r = 0; r < m; ++r) {
        for (int c = 0; c < n; ++c) {
            if (pacific[r][c] && atlantic[r][c]) {
                result.push_back({r, c});
            }
        }
    }
    return result;
}
```

```python
def pacificAtlantic(heights):
    def dfs(r, c, prev_height, visited):
        if not (0 <= r < len(heights)) or not (0 <= c < len(heights[0])):
            return
        if heights[r][c] >= prev_height and not visited[r][c]:
            visited[r][c] = True
            dfs(r - 1, c, heights[r][c], visited)
            dfs(r + 1, c, heights[r][c], visited)
            dfs(r, c - 1, heights[r][c], visited)
            dfs(r, c + 1, heights[r][c], visited)

    m, n = len(heights), len(heights[0])
    pacific = [[False] * n for _ in range(m)]
    atlantic = [[False] * n for _ in range(m)]

    for r in range(m):
        dfs(r, 0, -1, pacific)
        dfs(r, n - 1, -1, atlantic)
    for c in range(n):
        dfs(0, c, -1, pacific)
        dfs(m - 1, c, -1, atlantic)

    result = []
    for r in range(m):
        for c in range(n):
            if pacific[r][c] and atlantic[r][c]:
                result.append([r, c])
    return result
```


```java
public int wordsTyping(String[] sentence, int rows, int cols) {
    int totalChars = 0;
    for (String word : sentence) {
        totalChars += word.length() + 1;
    }

    int result = 0;
    int index = 0;
    for (int r = 0; r < rows; ++r) {
        int remainingCols = cols;
        while (true) {
            int wordLen = sentence[index].length();
            if (remainingCols >= wordLen) {
                remainingCols -= wordLen + 1;
                index = (index + 1) % sentence.length;
                if (index == 0) result++;
            } else {
                break;
            }
        }
    }

    return result;
}
```

sentence = \[ "hello ", "world "\], rows = 2, cols = 8

[ "apple ", "banana ", "cherry ", "dragonfruit ", "elderberry ", "fig ", "grape ", "honeydew ", "jackfruit ", "kiwi ", "lemon ", "mango ", "nectarine ", "orange ", "pineapple ", "quince ", "raspberry ", "strawberry ", "tomato ", "ugli fruit "]
20
30

[ "algorithm ", "programming ", "is ", "fun "]
2
8

[ "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine ", "ten ", "eleven ", "twelve ", "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen ", "twenty ", "twenty-one ", "twenty-two ", "twenty-three ", "twenty-four "]
20
30

[ "cat ", "dog ", "bird ", "elephant "]
4
10

[ "happy ", "sad ", "angry ", "surprised ", "afraid ", "confused ", "excited ", "scared ", "nervous ", "jolly ", "calm ", "peaceful ", "relaxed ", "anxious ", "bored ", "sick ", "tired ", "hungry ", "thirsty ", "drowsy ", "sleepy "]
20
30

[ "sun ", "moon ", "star ", "planet ", "comet "]
5
8

[ "cat ", "dog ", "fish ", "bird ", "elephant ", "lion ", "tiger "]
7
10

[ "the ", "quick ", "brown ", "fox ", "jumps ", "over ", "the ", "lazy ", "dog "]
3
8

[ "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine ", "ten ", "eleven ", "twelve ", "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen ", "twenty "]
20
20

[ "red ", "orange ", "yellow ", "green ", "blue ", "indigo ", "violet "]
7
10

[ "cat ", "dog ", "fish ", "bird ", "elephant ", "lion ", "tiger ", "wolf ", "fox ", "bear ", "horse ", "donkey ", "monkey ", "pig ", "rabbit ", "hamster ", "guinea pig ", "gerbil ", "rat ", "mouse ", "rat snake "]
20
30

[ "one ", "two ", "three ", "four ", "five ", "six "]
6
10

[ "apple ", "banana ", "cherry ", "dragonfruit ", "elderberry ", "fig ", "grape ", "honeydew ", "jackfruit ", "kiwi "]
10
15

[ "cat ", "dog ", "fish ", "bird ", "elephant ", "lion ", "tiger ", "wolf ", "fox ", "bear ", "horse ", "donkey ", "monkey ", "pig ", "rabbit ", "hamster ", "guinea pig ", "gerbil ", "rat ", "mouse ", "rat snake ", "armadillo ", "anteater "]
20
30

[ "red ", "orange ", "yellow ", "green ", "blue ", "indigo ", "violet ", "purple ", "pink ", "white "]
10
20

[ "happy ", "sad ", "angry ", "surprised ", "afraid ", "confused ", "excited ", "scared ", "nervous ", "jolly ", "calm ", "peaceful ", "relaxed ", "anxious ", "bored ", "sick ", "tired ", "hungry ", "thirsty ", "drowsy ", "sleepy ", "horny ", "aroused ", "energetic "]
20
30

[ "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine ", "ten ", "eleven ", "twelve ", "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen ", "twenty ", "twenty-one ", "twenty-two ", "twenty-three ", "twenty-four ", "twenty-five "]
20
30

[ "apple ", "banana ", "cherry ", "dragonfruit ", "elderberry ", "fig ", "grape ", "honeydew ", "jackfruit ", "kiwi ", "lemon ", "mango ", "nectarine ", "orange ", "pineapple ", "quince ", "raspberry ", "strawberry ", "tomato ", "ugli fruit ", "victoria plum ", "watermelon ", "xigua "]
20
30

[ "happy ", "sad ", "angry ", "surprised ", "afraid ", "confused ", "excited ", "scared ", "nervous ", "jolly "]
10
15

[ "longwordthatwillnotfit ", "on ", "oneline "]
3
8

[ "red ", "orange ", "yellow ", "green ", "blue ", "indigo ", "violet ", "purple ", "pink ", "white ", "black ", "gray ", "brown ", "navy ", "teal ", "cyan ", "magenta ", "silver ", "gold ", "bronze ", "tin "]
20
30

[ "red ", "green ", "blue ", "yellow ", "black ", "white "]
6
12

[ "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine ", "ten "]
10
10

[ "word ", "word ", "word ", "word "]
2
8

[ "cat ", "dog ", "fish ", "bird ", "elephant ", "lion ", "tiger ", "wolf ", "fox ", "bear "]
10
20

[ "happy ", "sad ", "angry ", "surprised ", "afraid "]
5
12

[ "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine ", "ten "]
4
8

[ "apple ", "banana ", "cherry ", "dragonfruit ", "elderberry "]
5
15

[ "apple ", "banana ", "cherry ", "dragonfruit ", "elderberry ", "fig ", "grape ", "honeydew ", "jackfruit ", "kiwi ", "lemon ", "mango ", "nectarine ", "orange ", "pineapple ", "quince ", "raspberry ", "strawberry ", "tomato ", "ugli fruit ", "victoria plum ", "watermelon ", "xigua ", "yellow passionfruit "]
20
30

[ "red ", "orange ", "yellow ", "green ", "blue ", "indigo ", "violet ", "purple ", "pink ", "white ", "black ", "gray ", "brown ", "navy ", "teal ", "cyan ", "magenta ", "silver ", "gold ", "bronze ", "tin ", "copper ", "iron "]
20
30

```cpp
int wordsTyping(vector<string>& sentence, int rows, int cols) {
    int total_chars = 0;
    for (const auto& word : sentence) {
        total_chars += word.size() + 1;
    }

    int result = 0;
    int index = 0;
    for (int r = 0; r < rows; ++r) {
        int remaining_cols = cols;
        while (true) {
            int word_len = sentence[index].size();
            if (remaining_cols >= word_len) {
                remaining_cols -= word_len + 1;
                index = (index + 1) % sentence.size();
                if (index == 0) result++;
            } else {
                break;
            }
        }
    }

    return result;
}
```


```cpp
int countBattleships(vector<vector<char>>& board) {
    int count = 0;
    for (int i = 0; i < board.size(); i++) {
        for (int j = 0; j < board[i].size(); j++) {
            if (board[i][j] == 'X' &&
                (i == 0 || board[i - 1][j] == '.') &&
                (j == 0 || board[i][j - 1] == '.')) {
                count++;
            }
        }
    }
    return count;
}
```

```python
def countBattleships(board):
    count = 0
    for i in range(len(board)):
        for j in range(len(board[0])):
            if (board[i][j] == 'X' and
                (i == 0 or board[i - 1][j] == '.') and
                (j == 0 or board[i][j - 1] == '.')):
                count += 1
    return count
```


```python
def findMaximumXOR(nums):
    max_xor = 0
    mask = 0

    for i in range(31, -1, -1):
        mask |= (1 << i)
        prefixes = {num & mask for num in nums}

        possible_max = max_xor | (1 << i)

        for prefix in prefixes:
            if prefix ^ possible_max in prefixes:
                max_xor = possible_max
                break

    return max_xor
```

```java
public int findMaximumXOR(int[] nums) {
    int max_xor = 0, mask = 0;

    for (int i = 31; i >= 0; i--) {
        mask |= (1 << i);
        HashSet<Integer> prefixes = new HashSet<>();

        for (int num : nums) {
            prefixes.add(num & mask);
        }

        int possible_max = max_xor | (1 << i);

        for (int prefix : prefixes) {
            if (prefixes.contains(prefix ^ possible_max)) {
                max_xor = possible_max;
                break;
            }
        }
    }

    return max_xor;
}
```


```java
public boolean validWordSquare(List<String> words) {
    for (int i = 0; i < words.size(); i++) {
        for (int j = 0; j < words.get(i).length(); j++) {
            if (j >= words.size() || i >= words.get(j).length() || words.get(i).charAt(j) != words.get(j).charAt(i)) {
                return false;
            }
        }
    }
    return true;
}
```

words = \[ "abcd ", "bnrt ", "crmy ", "dtye "\]

false false false false false false false false false false false false false false false false false false false false false false false false false false false false false true false false false false false false true false false false false false false

```cpp
bool validWordSquare(vector<string>& words) {
    for (int i = 0; i < words.size(); ++i) {
        for (int j = 0; j < words[i].size(); ++j) {
            if (j >= words.size() || i >= words[j].size() || words[i][j] != words[j][i]) {
                return false;
            }
        }
    }
    return true;
}
```


```cpp
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

string find_digits_in_ascending_order(string s) {
    vector<int> count(10, 0);
    for (char c : s) {
        if (c == 'z') count[0]++;
        if (c == 'w') count[2]++;
        if (c == 'u') count[4]++;
        if (c == 'x') count[6]++;
        if (c == 'g') count[8]++;
        if (c == 'o') count[1]++;  // o = one + two + four
        if (c == 'h') count[3]++;  // h = three + eight
        if (c == 'f') count[5]++;  // f = five + seven
        if (c == 's') count[7]++;  // s = six + seven
        if (c == 'i') count[9]++;  // i = five + six + eight + nine
    }
    count[1] -= count[0] + count[2] + count[4];
    count[3] -= count[8];
    count[5] -= count[4];
    count[7] -= count[6];
    count[9] -= count[5] + count[6] + count[8];

    string res;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < count[i]; j++) {
            res += to_string(i);
        }
    }
    return res;
}
```

oztneoerow abc zgh eoerowoztn fviefuro ztneoerowo owoztneoer owoztenoer neoerowoztn owoztneoer woztneoeer woztneoeer eert ztneoerow tneoerowoz owozrneoer neoerowoz zwxvutsrqponmlkjihgfedcba woztneoeer rowoztneoe rowoztneoe ztneoerowo owoztneoer eoerowoztne erowoztneo eoerowozt 0198765432 neoerowozt owotneoer tneoerowo erer123 erowoztne rowoztneoe owoztenoe higklmn erowoztneo owoztneoer owoztenor tneoerowoz oztneoerow

```java
public String findDigitsInAscendingOrder(String s) {
    int[] count = new int[10];
    for (char c : s.toCharArray()) {
        if (c == 'z') count[0]++;
        if (c == 'w') count[2]++;
        if (c == 'u') count[4]++;
        if (c == 'x') count[6]++;
        if (c == 'g') count[8]++;
        if (c == 'o') count[1]++;
        if (c == 'h') count[3]++;
        if (c == 'f') count[5]++;
        if (c == 's') count[7]++;
        if (c == 'i') count[9]++;
    }
    count[1] -= count[0] + count[2] + count[4];
    count[3] -= count[8];
    count[5] -= count[4];
    count[7] -= count[6];
    count[9] -= count[5] + count[6] + count[8];

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < count[i]; j++) {
            sb.append(i);
        }
    }
    return sb.toString();
}
```


```cpp
#include <string>
#include <algorithm>
using namespace std;

int characterReplacement(string s, int k) {
    int n = s.length();
    int left = 0, right = 0, maxFreq = 0, result = 0;
    int freq[26] = {0};

    for (right = 0; right < n; right++) {
        freq[s[right] - 'A']++;
        maxFreq = max(maxFreq, freq[s[right] - 'A']);

        if (right - left + 1 - maxFreq > k) {
            freq[s[left] - 'A']--;
            left++;
        }

        result = max(result, right - left + 1);
    }

    return result;
}
```

```java
public int characterReplacement(String s, int k) {
    int n = s.length();
    int left = 0, right = 0, maxFreq = 0, result = 0;
    int[] freq = new int[26];

    for (right = 0; right < n; right++) {
        freq[s.charAt(right) - 'A']++;
        maxFreq = Math.max(maxFreq, freq[s.charAt(right) - 'A']);

        if (right - left + 1 - maxFreq > k) {
            freq[s.charAt(left) - 'A']--;
            left++;
        }

        result = Math.max(result, right - left + 1);
    }

    return result;
}
```


```java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public List<List<String>> wordSquares(String[] words) {
    Map<String, List<String>> prefixMap = buildPrefixMap(words);
    List<List<String>> squares = new ArrayList<>();
    for (String word : words) {
        List<String> square = new ArrayList<>();
        square.add(word);
        searchSquares(1, words[0].length(), square, prefixMap, squares);
    }
    return squares;
}

private void searchSquares(int index, int length, List<String> square, Map<String, List<String>> prefixMap, List<List<String>> squares) {
    if (index == length) {
        squares.add(new ArrayList<>(square));
        return;
    }
    String prefix = buildPrefix(square, index);
    for (String word : prefixMap.getOrDefault(prefix, new ArrayList<>())) {
        square.add(word);
        searchSquares(index + 1, length, square, prefixMap, squares);
        square.remove(square.size() - 1);
    }
}

private String buildPrefix(List<String> square, int index) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < index; i++) {
        sb.append(square.get(i).charAt(index));
    }
    return sb.toString();
}

private Map<String, List<String>> buildPrefixMap(String[] words) {
    Map<String, List<String>> prefixMap = new HashMap<>();
    for (String word : words) {
        for (int i = 0; i <= word.length(); i++) {
            String prefix = word.substring(0, i);
            if (!prefixMap.containsKey(prefix)) {
                prefixMap.put(prefix, new ArrayList<>());
            }
            prefixMap.get(prefix).add(word);
        }
    }
    return prefixMap;
}
```

words = \[ "area ", "lead ", "wall ", "lady ", "ball "\]

acre care race ecar acer acer acer acer acer acer acer acer acer acer acer acer

abat baba atan atal tala lata lata lata lata lata lata lata lata lata lata lata lata

area lead wall lady ball able lane lena lane lane lane lane

[['wall', 'area', 'lead', 'lady'], ['ball', 'area', 'lead', 'lady']]

[['baba', 'abat', 'baba', 'atan'], ['baba', 'abat', 'baba', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal']]

[['baba', 'abat', 'baba', 'atan'], ['baba', 'abat', 'baba', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal']]

[['baba', 'abat', 'baba', 'atan'], ['baba', 'abat', 'baba', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal']]

[['baba', 'abat', 'baba', 'atan'], ['baba', 'abat', 'baba', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal']]

[['baba', 'abat', 'baba', 'atan'], ['baba', 'abat', 'baba', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal']]

[['baba', 'abat', 'baba', 'atan'], ['baba', 'abat', 'baba', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal']]

[['baba', 'abat', 'baba', 'atan'], ['baba', 'abat', 'baba', 'atal']]

[['baba', 'abat', 'baba', 'atan'], ['baba', 'abat', 'baba', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['tala', 'abat', 'lata', 'atan'], ['tala', 'abat', 'lata', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal'], ['lata', 'abat', 'tala', 'atan'], ['lata', 'abat', 'tala', 'atal']]

```python
from collections import defaultdict

def wordSquares(words):
    def build(row, squares, word_lens):
        if row == word_lens:
            res.append(list(squares))
            return
        prefix = ''.join(squares[i][row] for i in range(row))
        for w in prefixes[prefix]:
            squares[row] = w
            build(row+1, squares, word_lens)

    if not words: return []
    res = []
    word_lens = len(words[0])

    prefixes = defaultdict(list)
    for word in words:
        for i in range(word_lens+1):
            prefixes[word[:i]].append(word)

    for word in words:
        build(1, [word] + [None]*(word_lens-1), word_lens)

    return res
```


```python
from collections import deque

def minMutation(start, end, bank):
    q = deque([start])
    visited = set([start])
    depth = 0

    while q:
        levelSize = len(q)
        for _ in range(levelSize):
            current = q.popleft()
            if current == end:
                return depth

            for gene in bank:
                if gene not in visited:
                    diff = sum(1 for j in range(8) if current[j] != gene[j])
                    if diff == 1:
                        q.append(gene)
                        visited.add(gene)
        depth += 1
    return -1
```

startGene =  "AACCGGTT ", endGene =  "AACCGGTA ", bank = \[ "AACCGGTA "\]

AACCGGTT
AACCGGTT
["AACCGGTA", "AACCGGTC"]

AACCGGTT
AACCGGTC
["AACCGGTA", "AACCGGTC"]

AACCGGTT
TTTTTTTT
["AACCGGTA", "AACCGGTC", "TTTTTTTT"]

TTTTTTTT
TTTTTTTA
["TTTTTTTC", "TTTTTTCC", "TTTTTCTT"]

AAAACCCC
AAAAGCCC
["AAAACCCC", "AAAAGCCC", "AAAACCCC"]

AACCGGTT
CCCCCCCT
["CCCCCCCT", "AACCGGTA", "GGGCGGTT"]

TTTTTTTT
CCCCCCCC
["TTTTTTCC", "CCCCCCCC", "TTTTCCCC"]

AACCGGTT
GGGGGGGG
["AACCGGTA", "GGGGGGGG", "TTTTTTTT"]

```java
import java.util.*;

public int minMutation(String start, String end, String[] bank) {
    Queue<String> q = new LinkedList<>();
    q.offer(start);
    Set<String> visited = new HashSet<>();
    visited.add(start);
    int depth = 0;

    while (!q.isEmpty()) {
        int levelSize = q.size();
        for (int i = 0; i < levelSize; i++) {
            String current = q.poll();
            if (current.equals(end)) return depth;

            for (String gene : bank) {
                if (!visited.contains(gene)) {
                    int diff = 0;
                    for (int j = 0; j < 8; j++) {
                        if (current.charAt(j) != gene.charAt(j)) diff++;
                        if (diff > 1) break;
                    }

                    if (diff == 1) {
                        q.offer(gene);
                        visited.add(gene);
                    }
                }
            }
        }
        depth++;
    }
    return -1;
}
```


```java
import java.util.TreeMap;
import java.util.Map;

public int[] findRightInterval(int[][] intervals) {
    int[] res = new int[intervals.length];
    TreeMap<Integer, Integer> starts = new TreeMap<>();

    for(int i = 0; i < intervals.length; i++) {
        starts.put(intervals[i][0], i);
    }

    for(int i = 0; i < intervals.length; i++) {
        Map.Entry<Integer, Integer> right = starts.ceilingEntry(intervals[i][1]);
        res[i] = right == null ? -1 : right.getValue();
    }

    return res;
}
```

```python
def findRightInterval(intervals):
    starts = {interval[0]: index for index, interval in enumerate(intervals)}
    res = []

    for interval in intervals:
        right = min(filter(lambda x: x >= interval[1], starts.keys()), default=-1)
        res.append(starts[right] if right != -1 else -1)

    return res
```


```cpp
int pathSumHelper(TreeNode* node, int targetSum, int currentSum) {
    if (node == nullptr) {
        return 0;
    }

    currentSum += node->val;
    int totalPaths = currentSum == targetSum;
    totalPaths += pathSumHelper(node->left, targetSum, currentSum);
    totalPaths += pathSumHelper(node->right, targetSum, currentSum);
    return totalPaths;
}

int pathSum(TreeNode* root, int targetSum) {
    if (root == nullptr) {
        return 0;
    }

    return pathSumHelper(root, targetSum, 0) + pathSum(root->left, targetSum) + pathSum(root->right, targetSum);
}
```

```python
def path_sum_helper(node, target_sum, current_sum):
    if node is None:
        return 0

    current_sum += node.val
    total_paths = 1 if current_sum == target_sum else 0
    total_paths += path_sum_helper(node.left, target_sum, current_sum)
    total_paths += path_sum_helper(node.right, target_sum, current_sum)
    return total_paths

def path_sum(root, target_sum):
    if root is None:
        return 0

    return path_sum_helper(root, target_sum, 0) + path_sum(root.left, target_sum) + path_sum(root.right, target_sum)
```


```java
public int arrangeCoins(int n) {
    int k = 0;
    while (n > k) {
        k++;
        n -= k;
    }
    return k;
}
```

```python
def arrange_coins(n: int) -> int:
    k = 0
    while n > k:
        k += 1
        n -= k
    return k
```


```python
def find_duplicates(nums):
    duplicates = []
    for i in range(len(nums)):
        index = abs(nums[i]) - 1
        if nums[index] < 0:
            duplicates.append(abs(nums[i]))
        else:
            nums[index] *= -1
    return duplicates
```

```cpp
#include <vector>
#include <cmath>

std::vector<int> findDuplicates(std::vector<int>& nums) {
    std::vector<int> duplicates;
    for (int i = 0; i < nums.size(); i++) {
        int index = abs(nums[i]) - 1;
        if (nums[index] < 0) {
            duplicates.push_back(abs(nums[i]));
        } else {
            nums[index] *= -1;
        }
    }
    return duplicates;
}
```


```cpp
bool isShortestAndUniqueSupersequence(vector<int>& nums, vector<vector<int>>& sequences) {
    unordered_map<int, int> pos;
    for (int i = 0; i < nums.size(); ++i) {
        pos[nums[i]] = i;
    }

    for (const auto& seq : sequences) {
        if (pos[seq[0]] > pos[seq.back()]) {
            return false;
        }
    }
    return true;
}
```

false true false false true false false false false false false false false true false true false false false false false false false false false false true false false false true false false true false false true false true false true false true false false false false false false false true

```java
public boolean isShortestAndUniqueSupersequence(int[] nums, int[][] sequences) {
    Map<Integer, Integer> pos = new HashMap<>();
    for (int i = 0; i < nums.length; i++) {
        pos.put(nums[i], i);
    }

    for (int[] seq : sequences) {
        if (pos.get(seq[0]) > pos.get(seq[seq.length - 1])) {
            return false;
        }
    }
    return true;
}
```


```python
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def addTwoNumbers(l1, l2):
    result = ListNode(0)
    current = result
    carry = 0
    while l1 or l2 or carry:
        sum = (l1.val if l1 else 0) + (l2.val if l2 else 0) + carry
        carry = sum // 10
        current.next = ListNode(sum % 10)
        current = current.next
        if l1: l1 = l1.next
        if l2: l2 = l2.next
    return result.next
```

```cpp
struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(nullptr) {}
};

ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
    ListNode* result = nullptr;
    ListNode** current = &result;
    int carry = 0;
    while (l1 || l2 || carry) {
        int sum = (l1 ? l1->val : 0) + (l2 ? l2->val : 0) + carry;
        carry = sum / 10;
        *current = new ListNode(sum % 10);
        current = &((*current)->next);
        if (l1) l1 = l1->next;
        if (l2) l2 = l2->next;
    }
    return result;
}
```


```java
import java.util.HashMap;
import java.util.Map;

public int numberOfArithmeticSlices(int[] nums) {
    int res = 0;
    int n = nums.length;
    Map<Integer, Integer>[] dp = new HashMap[n];

    for (int i = 0; i < n; ++i) {
        dp[i] = new HashMap<>();
        for (int j = 0; j < i; ++j) {
            long diff = (long)nums[i] - (long)nums[j];
            if (diff <= Integer.MIN_VALUE || diff > Integer.MAX_VALUE) continue;

            int delta = (int)diff;
            dp[i].put(delta, dp[i].getOrDefault(delta, 0) + 1);

            if (dp[j].containsKey(delta)) {
                res += dp[j].get(delta);
                dp[i].put(delta, dp[i].get(delta) + dp[j].get(delta));
            }
        }
    }
    return res;
}
```

```python
def numberOfArithmeticSlices(nums):
    res = 0
    n = len(nums)
    dp = [dict() for _ in range(n)]

    for i in range(n):
        for j in range(i):
            diff = nums[i] - nums[j]
            if diff <= -2**31 or diff > 2**31:
                continue

            dp[i][diff] = dp[i].get(diff, 0) + 1

            if diff in dp[j]:
                res += dp[j][diff]
                dp[i][diff] += dp[j][diff]

    return res
```


```python
def numberOfBoomerangs(points):
    count = 0

    for i in points:
        group_count = {}
        for j in points:
            dx, dy = i[0] - j[0], i[1] - j[1]
            dist = dx * dx + dy * dy
            group_count[dist] = group_count.get(dist, 0) + 1

        for g in group_count.values():
            count += g * (g - 1)

    return count
```

```java
import java.util.HashMap;

public int numberOfBoomerangs(int[][] points) {
    int count = 0;

    for (int[] i : points) {
        HashMap<Integer, Integer> group_count = new HashMap<>();
        for (int[] j : points) {
            int dx = i[0] - j[0], dy = i[1] - j[1];
            int dist = dx * dx + dy * dy;

            group_count.put(dist, group_count.getOrDefault(dist, 0) + 1);
        }

        for (int g : group_count.values()) {
            count += g * (g - 1);
        }
    }

    return count;
}
```


```python
def find_disappeared_numbers(nums):
    result = []

    for num in nums:
        index = abs(num) - 1
        nums[index] = -abs(nums[index])

    for i, num in enumerate(nums):
        if num > 0:
            result.append(i + 1)

    return result
```

```cpp
#include <vector>
using namespace std;

vector<int> findDisappearedNumbers(vector<int> &nums) {
    vector<int> result;

    for (int i = 0; i < nums.size(); ++i) {
        int index = abs(nums[i]) - 1;
        nums[index] = -abs(nums[index]);
    }

    for (int i = 0; i < nums.size(); ++i) {
        if (nums[i] > 0) {
            result.push_back(i + 1);
        }
    }

    return result;
}
```


```java
import java.util.Arrays;
import java.util.Comparator;

public int findMinArrowShots(int[][] points) {
    if (points.length == 0) return 0;
    Arrays.sort(points, Comparator.comparingInt(a -> a[1]));

    int arrows = 1;
    int end = points[0][1];

    for (int i = 1; i < points.length; i++) {
        if (points[i][0] > end) {
            arrows++;
            end = points[i][1];
        }
    }

    return arrows;
}
```

```python
def findMinArrowShots(points):
    if not points:
        return 0
    points.sort(key=lambda x: x[1])

    arrows = 1
    end = points[0][1]

    for i in range(1, len(points)):
        if points[i][0] > end:
            arrows += 1
            end = points[i][1]

    return arrows
```


```python
def min_moves(nums):
    min_element = min(nums)
    moves = sum(num - min_element for num in nums)
    return moves
```

```java
public int minMoves(int[] nums) {
    int min_element = nums[0];
    for (int num : nums) {
        min_element = Math.min(min_element, num);
    }
    int moves = 0;
    for (int num : nums) {
        moves += (num - min_element);
    }
    return moves;
}
```


```python
def fourSumCount(nums1, nums2, nums3, nums4):
    hashMap = {}
    count = 0

    for i in nums1:
        for j in nums2:
            hashMap[i + j] = hashMap.get(i + j, 0) + 1

    for k in nums3:
        for l in nums4:
            count += hashMap.get(-(k + l), 0)

    return count
```

```java
import java.util.HashMap;

public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
    HashMap<Integer, Integer> hashMap = new HashMap<>();
    int count = 0;

    for (int i : nums1) {
        for (int j : nums2) {
            hashMap.put(i + j, hashMap.getOrDefault(i + j, 0) + 1);
        }
    }

    for (int k : nums3) {
        for (int l : nums4) {
            count += hashMap.getOrDefault(-(k + l), 0);
        }
    }

    return count;
}
```


```cpp
#include <vector>
#include <algorithm>

int findContentChildren(std::vector<int>& g, std::vector<int>& s) {
    std::sort(g.begin(), g.end());
    std::sort(s.begin(), s.end());
    int i = 0, j = 0;

    while (i < g.size() && j < s.size()) {
      if (s[j] >= g[i]) {
        i++;
      }

      j++;
    }

    return i;
}
```

```java
import java.util.Arrays;

public int findContentChildren(int[] g, int[] s) {
    Arrays.sort(g);
    Arrays.sort(s);
    int i = 0, j = 0;

    while (i < g.length && j < s.length) {
        if (s[j] >= g[i]) {
            i++;
        }

        j++;
    }

    return i;
}
```


```java
public boolean find132pattern(int[] nums) {
    int n = nums.length;
    int[] min = new int[n];
    min[0] = nums[0];
    for (int i = 1; i < n; ++i) {
        min[i] = Math.min(min[i - 1], nums[i]);
    }
    Stack<Integer> stack = new Stack<>();
    for (int j = n - 1; j >= 0; --j) {
        if (nums[j] > min[j]) {
            while (!stack.isEmpty() && stack.peek() <= min[j]) {
                stack.pop();
            }
            if (!stack.isEmpty() && stack.peek() < nums[j]) {
                return true;
            }
            stack.push(nums[j]);
        }
    }
    return false;
}
```

True True True False False False False False False

```python
def find132pattern(nums):
    third, stack = float('-inf'), []
    for num in reversed(nums):
        if num < third:
            return True
        while stack and stack[-1] < num:
            third = stack.pop()
        stack.append(num)
    return False
```


```java
public boolean circularArrayLoop(int[] nums) {
    int N = nums.length;
    for (int i = 0; i < N; i++) {
        int slow = i, fast = i;
        do {
            slow = getNextIndex(slow, nums);
            fast = getNextIndex(getNextIndex(fast, nums), nums);
        } while (slow != fast && nums[slow] * nums[fast] > 0);

        if (slow != fast) continue;
        boolean cycle = false;
        int start = slow;
        do {
            cycle |= getNextIndex(start, nums) == start;
            start = getNextIndex(start, nums);
        } while (start != slow);
        if (!cycle) return true;
    }
    return false;
}

int getNextIndex(int idx, int[] nums) {
    int N = nums.length;
    return ((idx + nums[idx]) % N + N) % N;
}
```

True True True True True True True True True

```python
def circularArrayLoop(nums: List[int]) -> bool:
    N = len(nums)
    for i in range(N):
        slow, fast = i, i
        while True:
            slow = getNextIndex(slow, nums)
            fast = getNextIndex(getNextIndex(fast, nums), nums)
            if slow != fast and nums[slow] * nums[fast] > 0:
                break
            if slow == fast:
                break
        else:
            continue
        cycle = False
        start = slow
        while start != slow:
            cycle |= getNextIndex(start, nums) == start
            start = getNextIndex(start, nums)
        if not cycle:
            return True
    return False

def getNextIndex(idx: int, nums: List[int]) -> int:
    N = len(nums)
    return (idx + nums[idx]) % N
```


```java
public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
    int pigs = 0;
    while (Math.pow((minutesToTest / minutesToDie) + 1, pigs) < buckets) {
        pigs++;
    }
    return pigs;
}
```

buckets = 4, minutesToDie = 15, minutesToTest = 15

```python
def poor_pigs(buckets, minutes_to_die, minutes_to_test):
    pigs = 0
    while (minutes_to_test // minutes_to_die + 1) ** pigs < buckets:
        pigs += 1
    return pigs
```


```java
public int hammingDistance(int x, int y) {
    int dist = 0, xorResult = x ^ y;
    while (xorResult != 0) {
        dist += xorResult & 1;
        xorResult >>= 1;
    }
    return dist;
}
```

```python
def hammingDistance(x: int, y: int) -> int:
    xorResult = x ^ y
    dist = 0
    while xorResult:
        dist += xorResult & 1
        xorResult >>= 1
    return dist
```


```cpp
int minMoves2(vector<int>& nums) {
    int n = nums.size();
    sort(nums.begin(), nums.end());
    int mid = nums[n / 2];
    int moves = 0;
    for (int i = 0; i < n; i++) {
        moves += abs(nums[i] - mid);
    }
    return moves;
}
```

```python
def min_moves2(nums):
    nums.sort()
    mid = nums[len(nums) // 2]
    moves = 0
    for num in nums:
        moves += abs(num - mid)
    return moves
```


```java
import java.util.HashMap;

public class Solution {
    public boolean canIWin(int maxChoosableInteger, int desiredTotal) {
        if (maxChoosableInteger >= desiredTotal) return true;
        if ((maxChoosableInteger * (maxChoosableInteger + 1)) / 2 < desiredTotal) return false;

        HashMap<Integer, Boolean> memo = new HashMap<>();
        int state = 0;
        return canWin(maxChoosableInteger, desiredTotal, state, memo);
    }

    private boolean canWin(int maxChoosableInteger, int desiredTotal, int state, HashMap<Integer, Boolean> memo) {
        if (desiredTotal <= 0) return false;
        if (memo.containsKey(state)) return memo.get(state);

        for (int i = 1; i <= maxChoosableInteger; i++) {
            int bitCheck = 1 << i;
            if ((state & bitCheck) == 0) {
                if (!canWin(maxChoosableInteger, desiredTotal - i, state | bitCheck, memo)) {
                    memo.put(state, true);
                    return true;
                }
            }
        }

        memo.put(state, false);
        return false;
    }
}
```

maxChoosableInteger = 10, desiredTotal = 11

True True False True True True True False True True True True True False False False True True False True True True True True False False True True True True False True True True True True True False False True False True True True False False False True True True True True False

```python
def canIWin(maxChoosableInteger, desiredTotal):
    if maxChoosableInteger >= desiredTotal: return True
    if (maxChoosableInteger * (maxChoosableInteger + 1)) // 2 < desiredTotal: return False

    memo = {}

    def canWin(state):
        if state in memo:
            return memo[state]
        for i in range(1, maxChoosableInteger + 1):
            bitCheck = 1 << i
            if (state & bitCheck) == 0:
                if not canWin(state | bitCheck):
                    memo[state] = True
                    return True

        memo[state] = False
        return False

    return canWin(0)
```


```java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public int minTransfers(int[][] transactions) {
    Map<Integer, Integer> balances = new HashMap<>();
    for (int[] transaction : transactions) {
        balances.put(transaction[0], balances.getOrDefault(transaction[0], 0) - transaction[2]);
        balances.put(transaction[1], balances.getOrDefault(transaction[1], 0) + transaction[2]);
    }

    List<Integer> debts = new ArrayList<>();
    for (int balance : balances.values()) {
        if (balance != 0) {
            debts.add(balance);
        }
    }
    return dfs(debts, 0);
}

private int dfs(List<Integer> debts, int start) {
    while (start < debts.size() && debts.get(start) == 0) {
        start++;
    }
    if (start == debts.size()) {
        return 0;
    }
    int result = Integer.MAX_VALUE;
    for (int i = start + 1; i < debts.size(); ++i) {
        if ((debts.get(start) > 0) != (debts.get(i) > 0)) {
            debts.set(i, debts.get(i) + debts.get(start));
            result = Math.min(result, 1 + dfs(debts, start + 1));
            debts.set(i, debts.get(i) - debts.get(start));
        }
    }
    return result;
}
```

```python
from collections import defaultdict

def minTransfers(transactions):
    balances = defaultdict(int)
    for transaction in transactions:
        balances[transaction[0]] -= transaction[2]
        balances[transaction[1]] += transaction[2]

    debts = [balance for balance in balances.values() if balance != 0]
    return dfs(debts, 0)

def dfs(debts, start):
    while start < len(debts) and debts[start] == 0:
        start += 1
    if start == len(debts):
        return 0
    result = float('inf')
    for i in range(start + 1, len(debts)):
        if (debts[start] > 0) != (debts[i] > 0):
            debts[i] += debts[start]
            result = min(result, 1 + dfs(debts, start + 1))
            debts[i] -= debts[start]
    return result
```


```python
def findSubstringInWraproundString(p: str) -> int:
    cnt = [0] * 26
    length = 0

    for i in range(len(p)):
        if i > 0 and (p[i] == chr(ord(p[i - 1]) + 1) or ord(p[i - 1]) - ord(p[i]) == 25):
            length += 1
        else:
            length = 1
        cnt[ord(p[i]) - ord('a')] = max(cnt[ord(p[i]) - ord('a')], length)

    return sum(cnt)
```

bacz abcde czcppbzabcp czcppbzabcppza czcppbzabcpp ab apcpp cac zacba zaa zbaa czcppbza abc czpp czcppbzabc a caaz zcppa zab zaac czcppbzabcppz a zcppbz zcpp zabcp czcppb a czcppbza czppa czcppbzabcppzabc czcppbzabcppza acza az zcppp czcppbzabcppz acz zac abcza zacp czcppbzabc czcppbzabcpp zabc z czcppbzabcppzab czcppbzab czcppbzabcppzab a zzb czcppbz zcppbz

```java
public int findSubstringInWraproundString(String p) {
    int[] cnt = new int[26];
    int length = 0;

    for (int i = 0; i < p.length(); i++) {
        if (i > 0 && (p.charAt(i) == p.charAt(i - 1) + 1 || p.charAt(i - 1) - p.charAt(i) == 25)) {
            length++;
        } else {
            length = 1;
        }
        cnt[p.charAt(i) - 'a'] = Math.max(cnt[p.charAt(i) - 'a'], length);
    }

    int sum = 0;
    for (int v : cnt) {
        sum += v;
    }
    return sum;
}
```