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
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.
You are driving a taxi along a road with 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.