ปานกลาง 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 กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก