All Posts

Leetcode 1146: Snapshot Array

You need to implement a data structure that captures snapshots of an array and allows retrieving the value at any given index at a specific snapshot.

Leetcode 1155: Number of Dice Rolls With Target Sum

You have n dice, each with k faces numbered from 1 to k. You need to calculate the number of ways to roll the dice such that the sum of the dice equals a target value. Return the result modulo (10^9 + 7).

Leetcode 1156: Swap For Longest Repeated Character Substring

You are given a string text. You can swap two characters in the string. The task is to find the length of the longest substring with repeated characters after the swap.

Leetcode 1161: Maximum Level Sum of a Binary Tree

Given the root of a binary tree, find the smallest level x (1-indexed) such that the sum of the values of nodes at level x is maximal. Each level of the tree corresponds to the distance from the root, with the root being level 1.

Leetcode 1162: As Far from Land as Possible

Given a square grid of size n x n containing only 0s (water) and 1s (land), find the water cell that is farthest from any land cell based on Manhattan distance, and return that distance. If the grid has no water or no land, return -1.

Leetcode 1170: Compare Strings by Frequency of the Smallest Character

Define a function f(s) as the frequency of the lexicographically smallest character in a non-empty string s. For example, for s = 'abc', f(s) = 1 because the smallest character is 'a', appearing once. Given an array of strings queries and another array words, return an array where each entry corresponds to the number of strings in words where f(W) is greater than f(queries[i]) for a given i.