All Posts

Leetcode 377: Combination Sum IV

Given an array of distinct positive integers nums and a target integer target, determine the number of possible combinations of elements from nums that sum up to target. You can use any element of nums multiple times in a combination. A combination is considered different if the sequence of numbers is different, even if the same numbers are used.

Leetcode 378: Kth Smallest Element in a Sorted Matrix

Given an n x n matrix where each row and column is sorted in ascending order, find the kth smallest element in the matrix. The matrix is sorted in both rows and columns, but the kth smallest element is the one in the sorted order, not necessarily distinct.

Leetcode 380: Insert Delete GetRandom O(1)

Design a data structure that supports three operations: insert, remove, and getRandom. The insert operation adds an element to the set if it is not already present. The remove operation removes an element from the set if it exists. The getRandom operation returns a random element from the set, with each element having an equal probability of being selected.

Leetcode 384: Shuffle an Array

You are given an integer array nums. Design an algorithm to randomly shuffle the array. All permutations of the array should be equally likely as a result of the shuffling.

Leetcode 393: UTF-8 Validation

You are given an array of integers data, where each integer represents one byte of data. Your task is to check whether this sequence of bytes forms a valid UTF-8 encoded string based on the UTF-8 encoding rules for 1 to 4 bytes characters.

Leetcode 396: Rotate Function

You are given an integer array nums of length n. For each rotation k, we define a function F(k) which is calculated as: F(k) = 0 * arrk[0] + 1 * arrk[1] + … + (n-1) * arrk[n-1]. The goal is to return the maximum value of F(k) for all possible k in the range from 0 to n-1.