All Posts

Leetcode 1984: Minimum Difference Between Highest and Lowest of K Scores

You are given a 0-indexed array nums where each element represents the score of a student. You need to select the scores of exactly k students such that the difference between the highest and the lowest score of the selected students is minimized. Your task is to return the minimum possible difference.

Leetcode 1991: Find the Middle Index in Array

Given a 0-indexed integer array ’nums’, find the leftmost index where the sum of elements to the left of that index is equal to the sum of elements to the right of that index. If such an index exists, return the smallest such index, otherwise return -1. The sum of the elements before the first index is considered 0, and similarly, the sum of elements after the last index is also 0.

Leetcode 1995: Count Special Quadruplets

Given a 0-indexed integer array ’nums’, return the number of distinct quadruplets (a, b, c, d) such that:

  • nums[a] + nums[b] + nums[c] == nums[d], and
  • a < b < c < d.

Leetcode 2000: Reverse Prefix of Word

You are given a string ‘word’ and a character ‘ch’. Reverse the portion of the string starting at index 0 and ending at the index of the first occurrence of ‘ch’. If ‘ch’ is not found, return the original string.

Leetcode 2006: Count Number of Pairs With Absolute Difference K

Given an integer array nums and an integer k, return the number of pairs (i, j) where i < j such that |nums[i] - nums[j]| == k.

Leetcode 2011: Final Value of Variable After Performing Operations

In a simplified programming language, there are only four operations: incrementing or decrementing a variable X by 1. You are given a list of operations that can either increment or decrement the value of X. Your task is to determine the final value of X after applying all the operations.