FastPrepBuddies Greater than Target 🦋

Buddies Greater than Target 🦋

The Trade Desk logoThe Trade DeskEasyOA
Learn

Problem statement

Once upon a time, in a realm of integers, there was a quest to find the first spot where the landscape changed dramatically. The adventurers were given a map called "numbers," guiding them through this numerical landscape. Their mission was to discover the very first location where the terrain rose sharply, where three consecutive points, represented by "numbers[i]," "numbers[i + 1]," and "numbers[i + 2]," stood higher than a certain threshold.

As they journeyed through this numerical expanse, they diligently searched for a place where the terrain shifted abruptly, where three consecutive points towered above the threshold. Should they find such a place, they would mark the index "i" and return triumphantly. Yet, if no such spot existed, they would sadly return with news of their quest's failure, marked by a return value of -1.

Their journey was not about speed, but about thorough exploration. So long as their method did not exceed a complexity greater than O(numbers.length2), they could traverse the landscape within the allotted time.

For original prompt, please refer to source image. 🐳

Function

tDeskGreaterThanThreshold(buddyList: int[], target: int) → int

Examples

Example 1

buddyList = [0, 1, 4, 3, 2, 5]target = 1return = 2

At the starting point, index 0, the trio of companions (buddyList[0], buddyList[1], buddyList[2]) includes 0 and 1, neither of which surpasses the threshold of 1. Moving to index 1, the companionship of (buddyList[1], buddyList[2], buddyList[3]) comprises 1, 4, and 3. However, only 4 exceeds the target value. It's not until index 2 that the trio (buddyList[2], buddyList[3], buddyList[4]) emerges, featuring all friends whose values surpass the threshold. Thus, the answer lies at index 2, where the landscape shifts dramatically.

Constraints

  • Unknown for now

More The Trade Desk problems

See The Trade Desk hiring insights
public int tDeskGreaterThanThreshold(int[] buddyList, int target) {
    // write your code here
}
buddyList[0, 1, 4, 3, 2, 5]
target1
expected2
Checking account…