FastPrepDynamic Kth Largest Queries
Problems/Dynamic Kth Largest Queries

Dynamic Kth Largest Queries

Amazon logoAmazonFULLTIMEONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an initial list of integer values and a stream of operations. The list changes over time as values are inserted.

Each operation is one of the following:

  • "insert": insert the accompanying value into the list.
  • "find": treat the accompanying value as k and return the current k-th largest value in the list.

Return the answers to all "find" operations in order.

Function

dynamicKthLargestQueries(initialValues: int[], operations: String[], values: int[]) → int[]

Examples

Example 1

initialValues = [3, 7, 1]operations = ["find", "insert", "insert", "find", "find"]values = [3, 4, 9, 2, 4]return = [1, 7, 3]

Initially the sorted values are [1,3,7], so the 3rd largest is 1. After inserting 4 and 9, the values are [1,3,4,7,9]; the 2nd largest is 7 and the 4th largest is 3.

Example 2

initialValues = [5]operations = ["insert", "find", "insert", "find"]values = [2, 1, 10, 2]return = [5, 5]

After inserting 2, the largest value is 5. After inserting 10, the 2nd largest value is still 5.

Constraints

  • operations.length == values.length
  • Each operation is either "insert" or "find".
  • For each "find" operation, 1 <= k <= the current list size.

More Amazon Onsite Interview questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Optimal Account BalancingONSITE INTERVIEW · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int[] dynamicKthLargestQueries(int[] initialValues, String[] operations, int[] values) {
      // write your code here
    }
}
Checking account…