All Posts

Leetcode 775: Global and Local Inversions

You are given an integer array nums of length n, which is a permutation of all integers in the range [0, n - 1]. A global inversion is a pair of indices (i, j) such that 0 <= i < j < n and nums[i] > nums[j]. A local inversion is a pair where 0 <= i < n - 1 and nums[i] > nums[i + 1]. Return true if the number of global inversions is equal to the number of local inversions.

Leetcode 777: Swap Adjacent in LR String

You are given a string start and a string result composed of the characters ‘L’, ‘R’, and ‘X’. A move consists of either replacing an occurrence of ‘XL’ with ‘LX’, or replacing an occurrence of ‘RX’ with ‘XR’. Return true if it is possible to transform start into result by applying a sequence of these moves.

Leetcode 779: K-th Symbol in Grammar

We build a sequence of rows starting with the string ‘0’ in the first row. For each subsequent row, every occurrence of ‘0’ from the previous row is replaced with ‘01’, and every occurrence of ‘1’ is replaced with ‘10’. Given two integers n and k, return the k-th (1-indexed) symbol in the n-th row.

Leetcode 781: Rabbits in Forest

In a forest, there are an unknown number of rabbits. We ask n rabbits, ‘How many rabbits of the same color as you are there?’ and collect their answers in an integer array answers, where answers[i] is the answer of the i-th rabbit. The task is to determine the minimum number of rabbits that could be in the forest.

Leetcode 784: Letter Case Permutation

Given a string s, you can transform every letter individually to either lowercase or uppercase. Digits remain unchanged. Your task is to generate a list of all possible strings that can be created by changing the case of the letters in the string.

Leetcode 785: Is Graph Bipartite?

You are given an undirected graph where each node is labeled between 0 and n - 1. The graph is represented as a 2D array, where graph[u] contains the nodes that are adjacent to node u. A graph is bipartite if its nodes can be divided into two sets such that every edge connects a node from one set to a node in the other set. Your task is to return true if the graph is bipartite, otherwise return false.