All Posts

Leetcode 1712: Ways to Split Array Into Three Subarrays

You are given an array of non-negative integers. Your task is to count the number of ways the array can be split into three contiguous non-empty subarrays: left, mid, and right. The sum of the elements in the left subarray should be less than or equal to the sum in the mid subarray, and the sum of the mid subarray should be less than or equal to the sum of the right subarray. Return the number of such good splits modulo 10^9 + 7.

Leetcode 1717: Maximum Score From Removing Substrings

You are given a string s and two integers x and y. You can perform two types of operations any number of times:

  1. Remove the substring “ab” and gain x points.
  2. Remove the substring “ba” and gain y points.

Each time a substring is removed, the characters are deleted from the string, and the corresponding points are added to your total score. Your task is to maximize the total score after applying these operations any number of times.

Leetcode 1718: Construct the Lexicographically Largest Valid Sequence

Given an integer n, find a sequence of length 2n - 1 that satisfies the following conditions:

  1. The integer 1 occurs once in the sequence.
  2. Each integer between 2 and n occurs twice in the sequence.
  3. For every integer i between 2 and n, the distance between the two occurrences of i is exactly i.
  4. The sequence should be lexicographically the largest possible sequence.

The sequence is considered lexicographically larger if, at the first position where the two sequences differ, the number in the first sequence is greater.

Leetcode 1721: Swapping Nodes in a Linked List

You are given a singly linked list and an integer k. The task is to swap the values of the kth node from the beginning of the list with the kth node from the end of the list. The list is 1-indexed.

Leetcode 1722: Minimize Hamming Distance After Swap Operations

You are given two integer arrays, source and target, both of length n, and an array allowedSwaps containing pairs of indices where swapping is allowed. You can perform multiple swaps between the specified pairs to minimize the Hamming distance between source and target. The Hamming distance is the number of indices where the elements of source and target differ.

Leetcode 1726: Tuple with Same Product

You are given an array of distinct positive integers nums. Your task is to count how many tuples (a, b, c, d) exist such that the product of a * b equals the product of c * d, where a, b, c, d are distinct elements of nums and a != b != c != d.