FastPrepArray With Set All
Problems/Array With Set All

Array With Set All

Microsoft logoMicrosoft● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in two Microsoft software engineering internship reviews. Both describe the same design question. It is a structure whose get, set and setAll calls each run in constant time. Neither gives sizes, a starting value, or what get returns for an index that was never set. The round is not named. Both describe three interviews held on one day. Two more reviews with only a month for a date mention it as well, and we use them only as extra evidence.

Here the structure is an array of n integers (n up to 10^5) that all start at 0. The calls come as up to 10^4 strings: set i v, get i and setAll v, with 0-based indices and values from -10^9 to 10^9. You return the answers of the get calls in order. The tests check only the answers. O(1) per operation is the design goal that the editorial explains.

Our version is about 85% the same as the reported questions.

Design an array of n integers, indexed from 0 to n - 1, where every element starts at 0. It supports three operations, and each should take O(1) time:

  • "set i v": store the value v at index i.
  • "get i": answer the current value at index i.
  • "setAll v": change every element to v.

Process operations in order and return the answers of all get operations, in order.

Function

processArray(n: int, operations: String[]) → int[]

Examples

Example 1

n = 3operations = ["set 0 5","get 0","get 2","setAll 7","get 0","set 1 4","get 1","get 2"]return = [5,0,7,4,7]

Index 0 is set to 5, so get 0 is 5, and index 2 was never written, so get 2 is 0. After setAll 7 every element is 7, so get 0 is 7. Index 1 is then set to 4: get 1 is 4, while get 2 is still 7.

Example 2

n = 2operations = ["set 1 -3","setAll 9","setAll -2","get 1","set 0 6","setAll 1","get 0"]return = [-2,1]

The later setAll -2 replaces the earlier setAll 9 and the value set at index 1, so get 1 is -2. Index 0 is set to 6, but the setAll 1 after it overwrites it, so get 0 is 1.

Constraints

  • 1 <= n <= 10^5 and 1 <= operations.length <= 10^4
  • Each operation is "set i v", "get i" or "setAll v", with integers written without leading zeros or a plus sign.
  • 0 <= i < n and -10^9 <= v <= 10^9

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Escape Room LeaderboardPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
  • Insert, Delete, And Get Random In Constant TimeAmazon · ONSITE INTERVIEW
  • Insert, Delete, And Get Random In Constant TimeGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Future-Effective Employee SalaryRippling · ONSITE INTERVIEWRippling interview questions
  • Insert, Delete, and Get Random in Constant TimeBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Randomized Collection with Duplicate ValuesOkta · ONSITE INTERVIEWOkta interview questions
  • Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Insert Delete GetRandom O(1)Charta Health · PHONE SCREENCharta Health interview questions
  • Portfolio Tickers with Constant-Time Random PickCitadel · PHONE SCREENCitadel interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[] processArray(int n, String[] operations) {
        // Write your code here.
    }
}
Checking account…