← 返回博客列表
Microsoft

🚨 Microsoft 2026 Codility OA 真题流出!110 分钟 2 道题,为何看似简单却挂了一大片?

2026-01-24

Recently, Microsoft's Codility OA has been widely distributed.

Many candidates' first reaction after seeing the problems: "Easy! This is just DP/Greedy!"

Don't be overconfident.

If you treat them as ordinary algorithm problems, even with Bug-Free code, you'll likely get rejected.

Our oavoservice team obtained the actual problems immediately and discovered countless hidden traps related to Engineering Judgment.

🔍 Why Are Microsoft Codility Problems "Tricky"?

Microsoft doesn't favor LeetCode Hard problems like Google/Meta, but it has a more annoying characteristic:

Long problem descriptions with complex business scenarios
Requires manual input/output handling
Extremely tricky edge cases
Slight deviation in DP state definition = complete failure

Moreover, Codility platform features:

This "blind coding" mode severely tests your mental resilience.

Yesterday, one of our UIUC students spent 40 minutes on the first problem, only to find 60% pass rate after submission. He panicked immediately. Without our senior mentor's real-time voice guidance: "Stay calm, there's an issue with your DP state transition, redefine the states!", he probably couldn't have finished the second problem.

Final result? 110 minutes, 2 problems, all passed. Secured the interview invitation.

Let me break down these hot problems today and show you where the traps are.

💻 Problem 1: Domino Sequence

🔍 Problem Core

Given an array A of length 2*N, representing N dominoes. Each domino consists of two numbers:

Correct domino sequence: Adjacent dominoes must have the same number on their touching parts.

Problem requirement: What's the minimum number of dominoes to remove so the remaining ones form a correct sequence?

Constraints:

Example Analysis

Example 1:

A = [2, 4, 1, 3, 4, 6, 2, 4, 1, 6]
Dominoes: (2,4), (1,3), (4,6), (2,4), (1,6)

Answer: 3

🤯 Why Are So Many People Failing This?

Most people's first reactions:

❌ "Isn't this just longest consecutive subsequence?"
❌ "Use greedy, connect whenever possible!"
❌ "Brute force enumerate all possibilities!"

Then they write increasingly messy code and realize they can't handle:

  1. How to define "connectable"?
  2. How to handle multiple possible starting points?
  3. How to ensure finding the global optimal solution?

✅ Correct Engineering Mindset

This is a "Longest Increasing Subsequence variant + DP" problem.

Key Insight

This is not "greedy", but "dynamic programming"!

💣 Hidden Traps

Trap 1: Array Index Conversion

# Wrong approach
left = A[i]  # ❌ What is this?

# Correct approach
left = A[2*i]      # i-th domino's left
right = A[2*i + 1]  # i-th domino's right

Trap 2: Edge Cases

Trap 3: DP Initialization

🎯 Perfect Implementation (Python)

def solution(A):
    if len(A) == 0:
        return 0
    
    n = len(A) // 2
    if n == 1:
        return 0
    
    # Build domino list
    dominoes = []
    for i in range(n):
        left = A[2 * i]
        right = A[2 * i + 1]
        dominoes.append((left, right))
    
    # DP: dp[i] represents longest sequence ending at i-th domino
    dp = [1] * n
    
    for i in range(1, n):
        for j in range(i):
            # If j-th domino's right equals i-th domino's left
            if dominoes[j][1] == dominoes[i][0]:
                dp[i] = max(dp[i], dp[j] + 1)
    
    # Longest sequence length
    max_keep = max(dp)
    
    # Number to remove
    return n - max_keep

⚡️ Time Complexity Optimization

The above solution is O(n²), which might TLE for N=50,000.

Optimization idea: Use HashMap to record longest sequence for each right value

def solution(A):
    if len(A) == 0:
        return 0
    
    n = len(A) // 2
    if n == 1:
        return 0
    
    # HashMap: right_value -> max_length
    max_len = {}
    overall_max = 1
    
    for i in range(n):
        left = A[2 * i]
        right = A[2 * i + 1]
        
        # Find longest sequence connectable to current domino's left
        current_len = max_len.get(left, 0) + 1
        
        # Update longest sequence ending with right
        max_len[right] = max(max_len.get(right, 0), current_len)
        
        overall_max = max(overall_max, current_len)
    
    return n - overall_max

Time Complexity: O(n)
Space Complexity: O(1) (since domino numbers only 1-6)

🔢 Problem 2: Maximum Sum of Three Non-Adjacent Elements

🔍 Problem Core

Given integer array A, select exactly 3 non-adjacent elements to maximize their sum.

Non-adjacent definition: The three element indices must satisfy any two indices differ by > 1.

Constraints:

Example Analysis

Example 1:

A = [8, -4, -7, -5, -5, -4, 8, 8]

Answer: 12

Example 2:

A = [-2, -8, 1, 5, -8, 4, 7, 6]

Answer: 15

Example 3 (negative case):

A = [-3, 0, -6, -7, -9, -5, -2, -6]

Answer: -9

🤯 Hidden Killer: Why Do 90% Fail?

Seemingly simple problem, actually has three fatal traps:

Trap 1: Brute Force Will TLE

# ❌ This will definitely fail
max_sum = float('-inf')
for i in range(n):
    for j in range(i+2, n):
        for k in range(j+2, n):
            max_sum = max(max_sum, A[i] + A[j] + A[k])

Time Complexity: O(n³), for N=100,000 will definitely timeout.

Trap 2: Greedy Selection of 3 Largest Will Fail

# ❌ Wrong approach
sorted_indices = sorted(range(n), key=lambda i: A[i], reverse=True)
# Then try to find 3 non-adjacent ones?

Counter example:

A = [10, 1, 1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 8]

Greedy completely fails with negative numbers!

Trap 3: Unclear DP State Definition

Many want to use DP but don't know how to define states:

# ❌ Wrong state
dp[i] = "max sum of first i elements"  # How many selected?

✅ Correct Engineering Mindset: Enumerate Middle Element + Preprocessing

Core Insight

Fix the middle element, problem becomes simple!

  1. Enumerate the second element's position j (the middle one)
  2. Find maximum in [0, j-2] (first element)
  3. Find maximum in [j+2, n-1] (third element)

Key optimization: Preprocess prefix/suffix maximum values

💣 Most Common Pitfall

Edge cases:

Negative number handling:

🎯 Perfect Implementation (Python)

def solution(A):
    n = len(A)
    
    # Boundary check
    if n < 5:
        return float('-inf')  # No solution possible
    
    # Preprocessing: prefix_max[i] represents max of [0, i]
    prefix_max = [float('-inf')] * n
    prefix_max[0] = A[0]
    for i in range(1, n):
        prefix_max[i] = max(prefix_max[i-1], A[i])
    
    # Preprocessing: suffix_max[i] represents max of [i, n-1]
    suffix_max = [float('-inf')] * n
    suffix_max[n-1] = A[n-1]
    for i in range(n-2, -1, -1):
        suffix_max[i] = max(suffix_max[i+1], A[i])
    
    # Enumerate middle element
    max_sum = float('-inf')
    for j in range(2, n-2):
        # First element from [0, j-2]
        first = prefix_max[j-2]
        # Third element from [j+2, n-1]
        third = suffix_max[j+2]
        
        current_sum = first + A[j] + third
        max_sum = max(max_sum, current_sum)
    
    return max_sum

Time Complexity: O(n)
Space Complexity: O(n)

💡 Reality Check: Microsoft Codility OA Is Really Not Suitable for Solo Attempts

Microsoft SDE TC (North America):

New Grad: $160k – $180k
SDE II: $200k – $250k

Yet the brutal reality of Codility OA:

Must handle input/output yourself
No interactive debugging
One edge case error = complete failure
One chance, might wait half a year

What we do at oavoservice is simple:

You write the code
Someone monitors state definitions
Someone monitors edge cases
Someone monitors time complexity
Stop you before TLE / going wrong

It's not that you can't do it, it's that going alone carries too much risk.

🚀 oavoservice: Your Perfect Score Expert

Facing Microsoft's engineering-heavy, detail-layered Codility OA, you need more than just answers – you need a professional technical team supporting you.

We provide:

Full Codility platform coverage: Familiar with platform characteristics, avoid hidden traps
Production-Level Code: Industrial-grade standards, not leetcode style
Real-time voice guidance: Senior engineers guide you during OA
Perfect score guarantee: No pass, no fee – we're confident in our expertise

Don't let one DP state transition or edge case block your path to a $200k Offer.

We consistently provide professional online assessment services for major tech companies like Microsoft, Google, and Amazon, guaranteeing perfect scores.

👉 Add WeChat now: Coding0201

Secure your Microsoft interview opportunity!