[LeetCode] Determine if a Cell Is Reachable at a Given Time

2849. Determine if a Cell Is Reachable at a Given Time

You are given four integers sx, sy, fx, fy, and a non-negative integer t.

In an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.

Return true if you can reach cell (fx, fy) after exactly t seconds\, or false otherwise.

A cell’s adjacent cells are the 8 cells around it that share at least one corner with it. You can visit the same cell several times.

Read more
[LeetCode] Points That Intersect With Cars

2848. Points That Intersect With Cars

You are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [starti, endi] where starti is the starting point of the ith car and endi is the ending point of the ith car.

Return the number of integer points on the line that are covered with any part of a car.

Read more
[System Design] Request Collapsing

Request Collapsing

Request collasping은 빈번한 요청을 그룹화하고, 비슷한 요청을 하나로 합쳐서 효율적으로 처리하고 네트워크 대역폭과 서버 부하를 줄이는 테크닉이다.

Read more
[System Design] Optimal Probabilistic Cache Stampede Prevention

Optimal Probabilistic Cache Stampede Prevention

캐시 스템피드는 캐시가 만료되었을 때 여러 요청이 동일한 캐시 항목을 갱신하기 위해 처리를 진행하는 현상이다. 이 포스트에서는 캐시 스템피드 문제를 완화 하기 위한 기존 전략들과 논문에서 공개된 전략들을 살펴본다.

Read more
[LeetCode] Find The K-th Lucky Number

2802. Find The K-th Lucky Number

We know that 4 and 7 are lucky digits. Also, a number is called lucky if it contains only lucky digits.

You are given an integer k, return the kth lucky number represented as a string.

Read more
[LeetCode] Maximal Range That Each Element Is Maximum in It

2832. Maximal Range That Each Element Is Maximum in It

You are given a 0-indexed array nums of distinct integers.

Let us define a 0-indexed array ans of the same length as nums in the following way:

  • ans[i] is the maximum length of a subarray nums[l..r], such that the maximum element in that subarray is equal to nums[i].

Return the array ans.

Note that a subarray is a contiguous part of the array.

Read more
[LeetCode] Maximum Coins Heroes Can Collect

2838. Maximum Coins Heroes Can Collect

There is a battle and n heroes are trying to defeat m monsters. You are given two 1-indexed arrays of positive integers heroes and monsters of length n and m, respectively. heroes[i] is the power of ith hero, and monsters[i] is the power of ith monster.

The ith hero can defeat the jth monster if monsters[j] <= heroes[i].

You are also given a 1-indexed array coins of length m consisting of positive integers. coins[i] is the number of coins that each hero earns after defeating the ith monster.

Return an array ans of length n where ans[i] is the maximum number of coins that the ith hero can collect from this battle.

Notes

  • The health of a hero doesn’t get reduced after defeating a monster.
  • Multiple heroes can defeat a monster, but each monster can be defeated by a given hero only once.
Read more
[LeetCode] Minimum Relative Loss After Buying Chocolates

2819. Minimum Relative Loss After Buying Chocolates

You are given an integer array prices, which shows the chocolate prices and a 2D integer array queries, where queries[i] = [ki, mi].

Alice and Bob went to buy some chocolates, and Alice suggested a way to pay for them, and Bob agreed.

The terms for each query are as follows:

  • If the price of a chocolate is less than or equal to ki, Bob pays for it.
  • Otherwise, Bob pays ki of it, and Alice pays the rest.

Bob wants to select exactly mi chocolates such that his relative loss is minimized, more formally, if, in total, Alice has paid ai and Bob has paid bi, Bob wants to minimize bi - ai.

Return an integer array ans where ans[i] is Bob’s minimum relative loss possible for queries[i].

Read more
[LeetCode] Smallest Number With Given Digit Product

2847. Smallest Number With Given Digit Product

Given a positive integer n, return a string representing the smallest positive integer such that the product of its digits is equal to n, or "-1" if no such number exists.

Read more
[Codeforces] Round 137 (Div. 2) E. Decoding GenomeRead more