All Posts

Leetcode 1395: Count Number of Teams

You are given a list of soldiers, each with a unique rating. You need to form teams of 3 soldiers from this list. A valid team is one where the soldiers’ ratings are either strictly increasing or strictly decreasing as we move from left to right in the team. The team must satisfy the condition that the indices (i, j, k) follow 0 <= i < j < k < n.

Leetcode 1409: Queries on a Permutation With Key

You are given a list of positive integers called queries, each between 1 and m. You need to process each element in queries sequentially according to the following rules:

  1. Initially, the permutation P is [1, 2, 3, ..., m].
  2. For each queries[i], find the index of queries[i] in the permutation P.
  3. After locating queries[i] in P, move it to the beginning of the list.
  4. Return the list of indices (positions) for each element in queries as they are processed.

Leetcode 1418: Display Table of Food Orders in a Restaurant

Given a list of customer orders in a restaurant, return a table where each row represents a table number and the columns represent the number of food items ordered at that table, sorted in lexicographical order.

Leetcode 1423: Maximum Points You Can Obtain from Cards

You are given an array cardPoints representing the points of cards arranged in a row. In each step, you can pick the first or the last card from the row. Your goal is to pick exactly k cards and maximize the sum of the points of the cards you select.

Leetcode 1424: Diagonal Traverse II

You are given a 2D array nums, where each sub-array represents a row in the grid. Your task is to return all the elements of nums in diagonal order, starting from the top-left to bottom-right diagonals, where the sum of the row and column indices is constant.

Leetcode 1431: Kids With the Greatest Number of Candies

You are given a list of integers representing the number of candies each kid has. You are also given an integer representing the number of extra candies. Your task is to return a boolean array indicating whether, after adding all the extra candies to each kid’s total, they will have the greatest number of candies among all the kids.