Microsoft 26NG OA Review|20 minutes to pass, both questions are "Microsoft style".

1,588 Views

Just had it done the other day. Microsoft 26NG OA,整个体验非常顺,一共两道题,总时长 20 分钟左右就提交完毕。整体难度中等、思路明确、没有太多坑点,属于微软一贯的风格:看重思维清晰、代码干净,而不是故意刁难。

因为从八月到现在已经做了上百场各大厂的 OA(Microsoft、Google、Amazon、TikTok、Meta 都扫了一轮),这次微软 OA 基本属于“看一眼就知道怎么写”的类型。这里把题目整理出来,同时写写我自己的思路,给还在准备的同学做个参考。

Microsoft 26NG OA Review|20 minutes to pass, both questions are "Microsoft style".

Q1 - Maximize Sum by Choosing from Two Arrays

Problem
Given two arrays r1 And r2 of the same length N, you must choose exactly k elements from r1 And n - k elements from r2.
At position I, you may choose either r1[i] or r2[i], but not both.
Return the maximum possible total sum.

Analysis of ideas

This question is actually a very classic "gain selection" (gain selection) problem, greedy direct seconds.

My approach is simple and consistent:

  1. Assume for a moment that r2 is selected for all positions
    • Because r2 chose n-k but we'll just select them all first and replace the k later.
    • Initial sum = sum(r2).
  2. Calculate the "gain from switching to r1" for each position.
gain[i] = r1[i] - r2[i]
  1. The larger the gain, the more r1 should be selected.
  2. Sort the gains from largest to smallest and select the top k gains
  3. Answer = sum(r2) + sum of the first k largest gains

Why is this greed optimal?

Since there are only two choices for each position and they are completely independent, maximizing the sum is maximizing the local gain, and gain ordering is the only reasonable strategy.

This question is basically in the typical style of Microsoft OA:
It's not hard, but it must be written cleanly and logically.

Q2 - Minimum Edits to Form the Lexicographically Smallest Palindrome

Problem
Given a string S, you are allowed to modify characters.
You want to make the string rearrangeable into a palindrome.
Among all solutions that require the minimum number of edits, return the lexicographically smallest possible palindrome.

Breakdown of key points

There is an ironclad rule for wanting a string to be rearranged into a palindrome:

At most, a character can appear an odd number of times.

So the question becomes two steps:

  1. Minimum modification → Turn odd count characters into even if possible.
  2. smallest dictionary sequence → Try to place small characters in the left half when constructing palindromes

Specific practices

① Statistical frequency, number of treatment odd times

  • Count all character frequencies
  • Find all odd numbered characters.
  • Each modification allows two odd → even
    → and thus the number of modifications is minimized = odd_count / 2

In order to keep the final echo dictionary order as small as possible, I'll prioritize large odd characters towards small ones, so that frequency processing and dictionary order optimization can be done at the same time.

② Constructs a palindrome with minimal dictionary ordering

With the frequency adjusted, the construction method is natural:

  • 左半部分:按照从小到大填(例如 ‘a’ → ‘z’)
  • Center character: if there is an odd, put the odd character with the smallest number of occurrences
  • Right half: write the left half backwards

The whole is then guaranteed to be the dictionary-ordered minimum solution in the least-modified scheme.

Overall experience with Microsoft 26NG OA

This OA returned to Microsoft's usual focus of examination:

  • Clear logical derivation
  • Fundamentals of data structures (arrays, frequency statistics, sorting)
  • Code style and detailing
  • It's not about showmanship, it's about consistency.

There aren't any tricky test cases or particularly complicated corner cases.
Just think through the logic and it's a straight AC.

I got through both questions in about 20 minutes, at a pace of 5-10 minutes per question.

If you are also preparing for Microsoft / Amazon / Google school recruitment OA

Programhelp Specializing in technical support services for OA of major manufacturers, we provide the following assistance for online review platforms such as HackerRank and CodeSignal:

  • Online assessment code assistance and implementation: covers arrays, strings, simulations, constructions, greediness, graph theory, DP, and other mainstream question types
  • Ensure that all test cases pass: Aim for runnable, maintainable code
  • Results oriented, no fee for no success
  • Multi-language supportJava / Python / C++

The whole process is accomplished through remote collaboration tools such as ToDesk, with a seamless interface and natural operation that does not affect the normal submission experience, and is applicable to all kinds of programming tests on platforms such as CodeSignal, HackerRank, and Codility.

We have accumulated a lot of understanding of OA question types and scoring mechanisms of major manufacturers (Microsoft / Google / Amazon / TikTok / Meta), and we are also familiar with the differences in the operating environments of different platforms, so we can help candidates maintain stable performance in a tight time frame.

author avatar
Jory Wang Amazon Senior Software Development Engineer
Amazon senior engineer, focusing on the research and development of infrastructure core systems, with rich practical experience in system scalability, reliability and cost optimization. Currently focusing on FAANG SDE interview coaching, helping 30+ candidates successfully obtain L5/L6 Offers within one year.
END
 0