All Posts

Leetcode 2120: Execution of All Suffix Instructions Staying in a Grid

You are given an n x n grid, with the top-left cell at (0, 0) and the bottom-right cell at (n - 1, n - 1). A robot starts at a given position startPos = [startrow, startcol] on the grid, and a string s representing a sequence of movement instructions: ‘L’ (move left), ‘R’ (move right), ‘U’ (move up), and ‘D’ (move down). The robot can execute the instructions starting from any index i in s, but it stops if it moves off the grid or runs out of instructions. Your task is to return an array answer where answer[i] represents the number of instructions the robot can execute if it starts from the ith instruction.

Leetcode 2138: Divide a String Into Groups of Size k

Given a string s and an integer k, partition the string into groups of size k. If the last group has fewer than k characters, append a fill character to complete it. Return an array of the groups.

Leetcode 2149: Rearrange Array Elements by Sign

You are given an integer array ’nums’ of even length consisting of an equal number of positive and negative integers. Rearrange the array such that every consecutive pair of integers has opposite signs, the order of integers with the same sign is preserved, and the array begins with a positive integer.

Leetcode 2154: Keep Multiplying Found Values by Two

You are given an array of integers ’nums’ and an integer ‘original’. Start with the number ‘original’ and search for it in the array. If found, multiply it by two. Repeat this process until ‘original’ is no longer found in ’nums’. Return the final value of ‘original’.

Leetcode 2161: Partition Array According to Given Pivot

You are given an integer array ’nums’ and a value ‘pivot’. Your task is to rearrange the elements in ’nums’ such that all elements less than ‘pivot’ appear before any element greater than ‘pivot’, and all elements equal to ‘pivot’ appear between the elements less than and greater than ‘pivot’. The relative order of the elements less than and greater than ‘pivot’ should be preserved.

Leetcode 2169: Count Operations to Obtain Zero

You are given two non-negative integers, num1 and num2. In each operation, subtract the smaller number from the larger one. Continue until one of the numbers becomes zero and return the number of operations performed.