1p3a Question · Jan 2026

Microsoft Online Assessment Lexicographically Smallest String Problem

Question Details

We are given a string S of length n. We are also given two integer arrays : arr and brr of same length m. Now arr[i] or brr[i] = 0..n-1 . Now in one operation we can choose any index j : 0 <= j < m. A

Full Details

We are given a string S of length n. We are also given two integer arrays : arr and brr of same length m. Now arr[i] or brr[i] = 0..n-1 . Now in one operation we can choose any index j : 0 <= j < m. And we can swap the characters in the string s at indices arr[j] and brr[j].

Return the lexicographically smallest string after applying the operation any number of times. Ex: s = "cab" arr = [0,0] brr = [1,2] First choose j = 1. So arr[1] = 0 and brr[1] = 2. Now swap the characters at these indices in the string s => s = "bac". Now choose j = 0. So arr[0] = 0 and brr[0] = 1. Now s = "abc". Final ans = "abc".

Constraints : s consists of only lower case letters. 0 <= n <= 10^5 arr[i] = brr[i] = 0...n-1. 0 <= m <= n

About This Question

This is a reported interview question from a microsoft interview for a swe role during the oa round reported in 2026.

It covers the following topics: Arrays, Strings .