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:
- Initially, the permutation
P
is[1, 2, 3, ..., m]
. - For each
queries[i]
, find the index ofqueries[i]
in the permutationP
. - After locating
queries[i]
inP
, move it to the beginning of the list. - Return the list of indices (positions) for each element in
queries
as they are processed.