FastPrepResizable Array-Backed Integer Set
Problems/Resizable Array-Backed Integer Set

Resizable Array-Backed Integer Set

The Walt Disney Company logoThe Walt Disney Company● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report explicitly asks for a set without a hash function, first using a fixed list and then growing and shrinking with data volume. The command adapter exposes both set semantics and resize behavior and matches the task at about 93%.

Implement a set without hashing by storing unique integers in a contiguous array. Process commands ADD value, REMOVE value, CONTAINS value, SIZE, and CAPACITY. Every command emits a string result: mutations and membership emit true/false; SIZE and CAPACITY emit a decimal integer.

The backing capacity starts at initialCapacity, doubles before inserting into a full array, and halves after removal when size is at most one quarter of capacity, never below the initial capacity. Preserve the relative order of remaining values.

Function

dynamicArraySet(operations: String[], initialCapacity: int) → String[]

Examples

Example 1

operations = ["ADD 4","ADD 7","ADD 4","CONTAINS 7","SIZE","CAPACITY"]initialCapacity = 2return = ["true","true","false","true","2","2"]

Duplicate insertion fails and capacity remains two.

Example 2

operations = ["ADD 1","ADD 2","ADD 3","CAPACITY","REMOVE 2","REMOVE 3","CAPACITY"]initialCapacity = 2return = ["true","true","true","4","true","true","2"]

The third insert grows to four; size one then triggers shrink to two.

Example 3

operations = ["REMOVE 9","CONTAINS 9","SIZE","CAPACITY"]initialCapacity = 3return = ["false","false","0","3"]

Missing removal is harmless and capacity never falls below its initial value.

Constraints

  • 1 <= initialCapacity <= 10^4.
  • 1 <= operations.length <= 10^4.
  • Values are signed 32-bit integers and commands are valid.

More The Walt Disney Company problems

  • Find All Paths for a Name in a File SystemPHONE SCREEN · Seen Nov 2026
  • Shortest Path with Directional Move CostsPHONE SCREEN · Seen Sep 2026
  • Helpdesk Ticket ProcessingONSITE INTERVIEW · Seen Aug 2026
All The Walt Disney Company interview questionsSee The Walt Disney Company hiring insights
Saved
class Solution {
    public String[] dynamicArraySet(String[] operations, int initialCapacity) {
        // Write your solution here.
    }
}
Checking account…