All Posts

Leetcode 825: Friends Of Appropriate Ages

You are given an integer array ages, where each element represents the age of a person on a social media platform. A person will not send a friend request to another person if any of the following conditions are true:

  1. The recipient’s age is less than or equal to half of the sender’s age plus 7.
  2. The recipient’s age is greater than the sender’s age.
  3. The recipient’s age is greater than 100 and the sender’s age is less than 100.

Otherwise, the sender can send a friend request. Return the total number of friend requests made between people.

Leetcode 826: Most Profit Assigning Work

You are given a list of jobs, each with a difficulty level and a profit value, and a list of workers, each with a certain ability. A worker can only complete jobs with a difficulty level that is at most equal to the worker’s ability. Each worker can complete at most one job, but jobs can be assigned to multiple workers. The goal is to calculate the maximum total profit by assigning the jobs to workers based on their abilities.

Leetcode 833: Find And Replace in String

You are given a string s and k replacement operations. Each replacement operation consists of an index, a source substring, and a target substring. For each operation, check if the source substring occurs at the given index in s. If it does, replace the substring with the target. All operations are performed simultaneously, meaning they do not affect each other’s indexing. The task is to return the modified string after all operations are applied.

Leetcode 835: Image Overlap

You are given two square binary matrices img1 and img2, both of size n x n. Each matrix consists of 0s and 1s. You are allowed to slide img1 over img2 in any direction (up, down, left, or right) without rotating the matrix. Your task is to find the maximum number of overlapping positions where both img1 and img2 have a 1 in the same position after performing a translation.

Leetcode 840: Magic Squares In Grid

Given a grid of integers, the task is to find how many 3x3 magic square subgrids are present in the given grid. A 3x3 magic square is a grid that contains distinct numbers from 1 to 9, such that each row, each column, and both diagonals have the same sum. The input grid can contain numbers ranging from 0 to 15, but only numbers between 1 and 9 are valid for forming a magic square.

Leetcode 845: Longest Mountain in Array

Given an integer array arr, you need to find the length of the longest subarray that forms a mountain. A mountain subarray has the following properties: it must have at least three elements, the elements strictly increase to a peak, and then strictly decrease after the peak. If no such subarray exists, return 0.