All Posts

Leetcode 2007: Find Original Array From Doubled Array

You are given an array changed, which may have been created by doubling each element of an original array and then shuffling the elements. Your task is to determine if changed can be converted back into the original array, where each element in the original array has its double present in changed. If changed is not a valid doubled array, return an empty array. If it is valid, return the original array.

Leetcode 2008: Maximum Earnings From Taxi

You are driving a taxi along a road with n points. Each point represents a location on the road. Passengers request rides from one point to another, and for each ride, you earn the distance traveled plus a tip. Your goal is to maximize your earnings by picking up passengers optimally. You can only carry one passenger at a time, and may pick up a new passenger at any point after dropping off the previous one.

Leetcode 2012: Sum of Beauty in the Array

You are given an integer array ’nums’. For each index i (1 <= i <= nums.length - 2), calculate the beauty of nums[i] based on the following conditions:

  • The beauty of nums[i] is 2 if for all indices j before i and for all indices k after i, nums[j] < nums[i] < nums[k].
  • The beauty of nums[i] is 1 if nums[i-1] < nums[i] < nums[i+1] but the previous condition is not met.
  • The beauty of nums[i] is 0 if neither of the above conditions holds.

Return the sum of beauty values for all nums[i] where 1 <= i <= nums.length - 2.

Leetcode 2013: Detect Squares

You are given a stream of 2D points on the XY-plane. Your task is to design an algorithm that adds new points into a data structure and counts how many sets of three points, along with a given query point, can form an axis-aligned square. An axis-aligned square is a square where the edges are parallel or perpendicular to the X-axis and Y-axis, with all sides of equal length.

Leetcode 2017: Grid Game

You are given a 2D grid of size 2 x n, where each cell contains points. Two robots play a game where they start at (0, 0) and aim to reach (1, n-1). The first robot moves first, collecting points along its path. Then, the second robot moves, trying to maximize the points it collects. The task is to find the number of points collected by the second robot if both play optimally.

Leetcode 2018: Check if Word Can Be Placed In Crossword

You are given an m x n matrix representing a crossword puzzle. The matrix contains lowercase English letters, empty spaces (’ ‘), and blocked cells (’#’). Given a word, determine if it can be placed horizontally or vertically in the crossword while adhering to the following constraints.