Interview Questions/Coding/Decoy Market Signal

Decoy Market Signal

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Decoy Market Signal

A market surveillance system receives a timeline of integer readings. A decoy pattern exists if there are three readings chosen in time order, at indices i, j, and k with i < j < k, where the first reading is smaller than the third and the third is smaller than the second. In other words, the values must form a low-high-middle shape while keeping their original index order. The values do not need to be adjacent. Input Format: You are given an integer array readings. Output Format: Return true if such a decoy market signal exists, otherwise return false.

Examples

Example 1
Input:
readings = [1, 2, 3, 4]
Output:
false

Explanation: No indices i < j < k satisfy readings[i] < readings[k] < readings[j], so the output is false.

Approach hint

Think of the pattern as small, large, middle.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp