Free beta: free to use with daily limits while we build. Join the waitlist for founding-member pricing at launch. Join the waitlist

Sign up free

Oracle interview question

Shortest contiguous window that contains given elements at least a required number of times

Company:
Oracle
Type:
Coding
Difficulty:
Hard
Reported:
November 18, 2026

Problem

You are given an array nums and a set of required elements, each with a minimum number of occurrences, given as a map required from element to count. Find the shortest contiguous window (subarray) of nums in which every required element appears at least its required number of times.

In this version the function returns the window's elements as a list. The problem does not say which window to return when several shortest windows exist, what to return when no window qualifies, or how to treat empty requirements or a required count of 0 or less; ask the interviewer.

Example 1

Input: nums = [1, 2, 2, 3, 1, 2], required = {2: 2, 1: 1}
Output: [1, 2, 2]

The window at indices 0 to 2 has two 2s and one 1, and no window of length 2 can hold three required items.

Example 2

Input: nums = [5, 1, 5, 5], required = {5: 3}
Output: [5, 1, 5, 5]

The three 5s are spread over the whole array, so the only qualifying window is the array itself.

Constraints

  • Not stated; ask the interviewer.

Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern