Given an array of integers, find the longest subarray where the absolute difference between any two elements is less than or equal to .
Example
There are two subarrays meeting the criterion: and . The maximum length subarray has elements.
Given an array of integers, find the longest subarray where the absolute difference between any two elements is less than or equal to .
Example
There are two subarrays meeting the criterion: and . The maximum length subarray has elements.
Two cats and a mouse are at various positions on a line. You will be given their starting positions. Your task is to determine which cat will reach the mouse first, assuming the mouse does not move and the cats travel at equal speed. If the cats arrive at the same time, the mouse will be allowed to move and it will escape while they fight.
You are given queries in the form of , , and representing the respective positions for cats and , and for mouse . Complete the function to return the appropriate answer to each query, which will be printed on a new line.
Cat A
.Cat B
.Mouse C
as the two cats fight and mouse escapes.A person wants to determine the most expensive computer keyboard and USB drive that can be purchased with a give budget. Given price lists for keyboards and USB drives and a budget, find the cost to buy them. If it is not possible to buy both items, return .
Example
The person can buy a , or a . Choose the latter as the more expensive option and return .
Function Description
Complete the getMoneySpent function in the editor below.
getMoneySpent has the following parameter(s):
An avid hiker keeps meticulous records of their hikes. During the last hike that took exactly steps, for every step it was noted if it was an uphill, , or a downhill, step. Hikes always start and end at sea level, and each step up or down represents a unit change in altitude. We define the following terms:
Given the sequence of up and down steps during a hike, find and print the number of valleys walked through.