All Posts

Leetcode 856: Score of Parentheses

Given a balanced parentheses string, calculate the score of the string. The score is computed as follows:

  1. The score of ‘()’ is 1.
  2. For a concatenation of two balanced parentheses strings, AB, the score is the sum of their individual scores (A + B).
  3. For a balanced parentheses string wrapped in another pair of parentheses, (A), the score is twice the score of A (2 * A).

Leetcode 859: Buddy Strings

You are given two strings, s and goal, consisting of lowercase letters. Your task is to determine whether you can swap exactly two characters in s so that the resulting string matches goal. If this is possible, return true, otherwise return false. The swap is defined as selecting two different indices i and j, and swapping the characters at those positions in s.

Leetcode 880: Decoded String at Index

You are given an encoded string consisting of letters and digits. The string is decoded such that for each digit, the preceding segment of the decoded string is repeated (digit - 1) additional times. Your task is to return the kth character (1-indexed) in the decoded string, where k is a positive integer. The decoded string could be extremely large, so you are not expected to fully decode the string.

Leetcode 893: Groups of Special-Equivalent Strings

You are given an array of strings where each string is of the same length. In one move, you can swap any two characters at even indexed positions or any two characters at odd indexed positions in a string. Two strings are considered special-equivalent if they can be made identical after performing any number of such moves. Your task is to determine how many distinct groups of special-equivalent strings exist in the given array.

Leetcode 916: Word Subsets

Given two arrays of strings words1 and words2, find all the strings in words1 that are universal. A string from words1 is considered universal if it contains all the letters of every string in words2, including multiplicity. Each string in words2 is a subset of the string from words1.

Leetcode 921: Minimum Add to Make Parentheses Valid

You are given a string consisting of parentheses. In one move, you can insert a parenthesis (either ‘(’ or ‘)’) at any position in the string. Your task is to return the minimum number of moves required to make the string valid, meaning all parentheses are properly balanced.