PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Pinduoduo

Find next greater element for subset

Last updated: Mar 29, 2026

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.

Related Interview 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)
Pinduoduo logo
Pinduoduo
Feb 19, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
3
0

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]

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Pinduoduo•More Software Engineer•Pinduoduo Software Engineer•Pinduoduo Coding & Algorithms•Software Engineer Coding & Algorithms
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.