All Posts
Leetcode 2016: Maximum Difference Between Increasing Elements
You are given an integer array nums of size n. Your task is to find the maximum difference between two elements in the array such that the element on the right is strictly greater than the element on the left. Specifically, you need to find the largest difference between nums[j] - nums[i] where 0 <= i < j < n and nums[i] < nums[j]. If no such valid pair exists, return -1.
Leetcode 2022: Convert 1D Array Into 2D Array
You are given a 1D integer array called ‘original’ and two integers ’m’ and ’n’. Your task is to convert this 1D array into a 2D array with ’m’ rows and ’n’ columns. The elements from the ‘original’ array should be placed row-wise in the new 2D array.
Leetcode 2027: Minimum Moves to Convert String
s
consisting of n
characters, where each character is either ‘X’ or ‘O’. A move consists of selecting three consecutive characters in the string and converting them all to ‘O’. If a character is already ‘O’, it remains unchanged. Determine the minimum number of moves required to convert all the characters of s
to ‘O’.
You are given a string Leetcode 2037: Minimum Number of Moves to Seat Everyone
You are given two arrays: one representing the available seats in a row and the other representing the students who need to be seated. Each element in the arrays corresponds to a student’s desired seat or the position of an available seat. The task is to determine the minimum number of moves required to seat all students. A move consists of moving a student from one seat to another.
Leetcode 2047: Number of Valid Words in a Sentence
A sentence consists of lowercase letters (‘a’ to ‘z’), digits (‘0’ to ‘9’), hyphens (’-’), punctuation marks (’!’, ‘.’, and ‘,’), and spaces (’ ‘) only. A token is any sequence of characters separated by spaces. A token is considered a valid word if all the following conditions are met:
- It does not contain any digits.
- It contains at most one hyphen (’-’), and if present, the hyphen must be surrounded by lowercase letters.
- It contains at most one punctuation mark, and if present, the punctuation mark must be at the end of the token.
Given a sentence, count the number of tokens that are valid words.