All Posts

Leetcode 1222: Queens That Can Attack the King

On an 8x8 chessboard, there are multiple black queens and one white king. You are given the positions of the black queens and the white king. Your task is to find all the black queens that can directly attack the white king. A queen can attack the king if they share the same row, column, or diagonal.

Leetcode 1389: Create Target Array in the Given Order

Given two arrays of integers nums and index, the task is to create a target array by inserting elements of nums at the positions specified by index. After processing all elements, return the target array.

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 1441: Build an Array With Stack Operations

You are given a strictly increasing integer array target and an integer n. Starting with an empty stack, you can perform two operations: ‘Push’ to add an integer to the stack and ‘Pop’ to remove the top element from the stack. A stream of integers from 1 to n is provided. Use the stack operations to build the stack so that it contains the elements of target in order (from bottom to top). Return the sequence of operations required. Stop processing once the stack equals the target array.

Leetcode 1503: Last Moment Before All Ants Fall Out of a Plank

You are given a wooden plank of length n, and some ants are walking on the plank. Some ants move to the left, others to the right. When two ants meet, they change directions without any additional time loss. When an ant reaches the edge of the plank, it falls off. The task is to determine when the last ant will fall off the plank.

Leetcode 1535: Find the Winner of an Array Game

You are given an array of distinct integers and an integer k. The game is played between the first two elements of the array. In each round, the larger integer wins and remains at position 0, while the smaller integer moves to the end of the array. The game ends when one integer wins k consecutive rounds. Your task is to return the integer that wins the game.