मध्यम 0 हल किए गए 0% स्वीकृति

Nearest Smaller Value to the Left

For each number, find the closest earlier position containing a strictly smaller number.

समस्या

For each number, find the closest earlier position containing a strictly smaller number. Equal numbers do not qualify. Positions start at 1; use 0 when there is no smaller number to the left.

Implement nearest_smaller_value(numbers).

Input

numbers: Numbers in their original order.

Output

Return one earlier position (or 0) for every input value.

सीमाएँ

0…200,000 integers, each between −1,000,000,000 and 1,000,000,000. Empty input returns an empty list.

उदाहरण

उदाहरण 1
इनपुट:
numbers = [4, 2, 5, 3]

अपेक्षित आउटपुट:
expected = [0, 0, 2, 2]
इनपुट:
std::vector<long long> numbers = {4, 2, 5, 3};

अपेक्षित आउटपुट:
std::vector<long long> expected = {0, 0, 2, 2};
इनपुट:
long[] numbers = new long[] {4, 2, 5, 3};

अपेक्षित आउटपुट:
long[] expected = new long[] {0, 0, 2, 2};

व्याख्या

4 has no earlier value and 2 has no smaller earlier value. Both 5 and 3 find the value 2 at position 2.

उदाहरण 2
इनपुट:
numbers = [2, 2, 2]

अपेक्षित आउटपुट:
expected = [0, 0, 0]
इनपुट:
std::vector<long long> numbers = {2, 2, 2};

अपेक्षित आउटपुट:
std::vector<long long> expected = {0, 0, 0};
इनपुट:
long[] numbers = new long[] {2, 2, 2};

अपेक्षित आउटपुट:
long[] expected = new long[] {0, 0, 0};

व्याख्या

Earlier equal values are not strictly smaller. Every answer is 0.

संदर्भ

यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।