[AlgoExpert] Knuth Morris Pratt AlgorithmRead more
[AlgoExpert] Non-Attacking QueensRead more
[AlgoExpert] Longest Balanced SubstringRead more
[AlgoExpert] Node SwapRead more
[AlgoExpert] Airport ConnectionsRead more
[AlgoExpert] Longest String ChainRead more
[AlgoExpert] Square of ZeroesRead more
[LeetCode] Check if There Is a Valid Parentheses String Path

2267. Check if There Is a Valid Parentheses String Path

A parentheses string is a non-empty string consisting only of ‘(‘ and ‘)’. It is valid if any of the following conditions is true:

  • It is ().
  • It can be written as AB (A concatenated with B), where A and B are valid parentheses strings.
  • It can be written as (A), where A is a valid parentheses string.

You are given an m x n matrix of parentheses grid. A valid parentheses string path in the grid is a path satisfying all of the following conditions:

  • The path starts from the upper left cell (0, 0).
  • The path ends at the bottom-right cell (m - 1, n - 1).
  • The path only ever moves down or right.
  • The resulting parentheses string formed by the path is valid.

Return true if there exists a valid parentheses string path in the grid. Otherwise, return false.

Read more
[LeetCode] Count Number of Texts

2266. Count Number of Texts

Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below.

In order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of the letter in the key.

  • For example, to add the letter ‘s’, Alice has to press ‘7’ four times. Similarly, to add the letter ‘k’, Alice has to press ‘5’ twice.
  • Note that the digits ‘0’ and ‘1’ do not map to any letters, so Alice does not use them.

However, due to an error in transmission, Bob did not receive Alice’s text message but received a string of pressed keys instead.

  • For example, when Alice sent the message “bob”, Bob received the string “2266622”.

Given a string pressedKeys representing the string received by Bob, return the total number of possible text messages Alice could have sent.

Since the answer may be very large, return it modulo 109 + 7.

Read more
[LeetCode] Make Array Non-decreasing or Non-increasing

2263. Make Array Non-decreasing or Non-increasing

You are given a 0-indexed integer array nums. In one operation, you can:

  • Choose an index i in the range 0 <= i < nums.length
  • Set nums[i] to nums[i] + 1 or nums[i] - 1

Return the minimum number of operations to make nums non-decreasing or non-increasing.

Read more