Problem Name: Next Greater Element I
Problem Statement:
Given two arrays of integers
and
, find the
index of each element in
.
More formally, given a list of numbers
and a list of indices
from a separate list of numbers
, determine the next greater number for each element at the given index in
.
Rules and Constraints:
- The function should return a list of indices where elements from are in in ascending order of their corresponding indices, and each index is a position within the list .
- For each index in where the element in is the largest element, the answer will be -1.
Notes:
This problem assumes that the input arrays are valid, with
containing unique integers and
containing integers without duplicates.
The goal is to write an efficient algorithm to solve this problem, focusing on optimizing time complexity.
Input/Output Format:
Two arrays,
and
, will be provided. The output will be an array of indices, each index pointing to a value in
corresponding to each element in
in the ascending order of its index within
.
Example
Input: {"nums1":[4,1,2],"nums2":[1,3,4,2]}
Output: [-1,3,-1]