All Posts

Leetcode 2096: Step-By-Step Directions From a Binary Tree Node to Another

You are given a binary tree where each node has a unique value between 1 and n. You are also given a start node and a destination node, each represented by their values. Your task is to find the shortest path from the start node to the destination node in terms of directions. The directions should be represented by a string using the characters ‘L’, ‘R’, and ‘U’, where ‘L’ means left child, ‘R’ means right child, and ‘U’ means moving to the parent node.

Leetcode 2108: Find First Palindromic String in the Array

Given a list of words, return the first word that is a palindrome. A palindrome is a word that reads the same forwards and backwards. If no palindromic word is found, return an empty string.

Leetcode 2109: Adding Spaces to a String

You are given a string s and an array spaces. The array contains indices where spaces need to be inserted into the string. Each space should be added before the character at the respective index. Return the modified string with the spaces inserted.

Leetcode 2116: Check if a Parentheses String Can Be Valid

You are given a string s consisting of parentheses ‘(’ and ‘)’, and a binary string locked of the same length. Each position in locked determines whether the corresponding character in s can be changed or not. If locked[i] is ‘1’, the character s[i] cannot be modified, but if locked[i] is ‘0’, you can change s[i] to either ‘(’ or ‘)’. Your task is to determine if it is possible to make the string s a valid parentheses string by changing the positions where locked[i] is ‘0’. A valid parentheses string is defined by the following conditions: It is either ‘()’, or a concatenation of valid parentheses strings, or it can be written as (A) where A is a valid parentheses string.

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 2124: Check if All A's Appears Before All B's

You are given a string consisting of only the characters ‘a’ and ‘b’. Your task is to determine if all occurrences of ‘a’ appear before all occurrences of ‘b’ in the string. If that is the case, return true; otherwise, return false.