PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of sequence analysis and array-processing competencies, including mapping elements between arrays, index lookup, and designing efficient order-dependent algorithms for the "next greater element" problem.

  • easy
  • Pinduoduo
  • Coding & Algorithms
  • Software Engineer

Find next greater element for subset

Company: Pinduoduo

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Onsite

You are given two integer arrays `query` and `nums`. - All elements in `nums` are distinct. - Every element in `query` also appears in `nums`. For each value `x` in `query`, find the **next greater element** of `x` in `nums`: the first element to the right of `x`'s position in `nums` that is strictly greater than `x`. If no such element exists, return `-1` for that `x`. Return an array `ans` of the same length as `query`, where `ans[i]` is the next greater element for `query[i]`. Example: - `query = [4, 1, 2]`, `nums = [1, 3, 4, 2]` → `ans = [-1, 3, -1]`

Quick Answer: This question evaluates understanding of sequence analysis and array-processing competencies, including mapping elements between arrays, index lookup, and designing efficient order-dependent algorithms for the "next greater element" problem.

For each query value, return the first greater value to its right in nums, or -1.

Examples

Input: ([4, 1, 2], [1, 3, 4, 2])

Expected Output: [-1, 3, -1]

Explanation: Prompt example.

Input: ([2, 4], [1, 2, 3, 4])

Expected Output: [3, -1]

Explanation: One has no greater.

Input: ([1], [1])

Expected Output: [-1]

Explanation: Single value.

Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Shortest Square-Sum Path - Pinduoduo (hard)
  • Compute User Login Streaks - Pinduoduo (easy)
  • Determine Straight Flush - Pinduoduo (easy)
  • Design a Recency-Eviction Cache - Pinduoduo (medium)
  • Find missing rank in a straight - Pinduoduo (easy)