Microsoft Placement Papers 2024
Access 2024 Microsoft OA questions with solutions and exam pattern analysis.
Practice with 25+ Microsoft placement paper coding questions covering DSA problems, algorithms, and system design concepts. These questions are representative of what you’ll encounter in Microsoft’s online assessment and technical interviews.
What’s Included:
Microsoft Placement Papers 2024
Access 2024 Microsoft OA questions with solutions and exam pattern analysis.
Microsoft Placement Papers 2025
Practice latest 2025 Microsoft OA questions with updated patterns.
Complete Microsoft guide
Access complete Microsoft placement papers guide with eligibility, process, and preparation strategy.
Microsoft Online Assessment Breakdown:
| Section | Questions | Time | Difficulty | Focus Areas |
|---|---|---|---|---|
| Coding Test | 3-4 | 90 min | Medium-Hard | Arrays, trees, graphs, DP, system design |
Languages Allowed: C, C++, Java, Python, C#
Problem: Find indices of two numbers that add up to target.
Example:
Input: nums = [2, 7, 11, 15], target = 9Output: [0, 1]Solution (C++):
vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int, int> map; for (int i = 0; i < nums.size(); i++) { int complement = target - nums[i]; if (map.find(complement) != map.end()) { return {map[complement], i}; } map[nums[i]] = i; } return {};}Solution (Python):
def two_sum(nums, target): seen = {} for i, num in enumerate(nums): if target - num in seen: return [seen[target - num], i] seen[num] = i return []Time Complexity: O(n) | Space Complexity: O(n)
Problem: Check if string with brackets is valid.
Example:
Input: "()[]{}"Output: trueSolution (C++):
bool isValid(string s) { stack<char> st; unordered_map<char, char> pairs = {{')', '('}, {'}', '{'}, {']', '['}};
for (char c : s) { if (pairs.count(c)) { if (st.empty() || st.top() != pairs[c]) return false; st.pop(); } else { st.push(c); } } return st.empty();}Solution (Python):
def is_valid(s): stack = [] mapping = {')': '(', '}': '{', ']': '['} for char in s: if char in mapping: if not stack or stack.pop() != mapping[char]: return False else: stack.append(char) return len(stack) == 0Time Complexity: O(n) | Space Complexity: O(n)
Problem: Reverse a singly linked list.
Solution (C++):
ListNode* reverseList(ListNode* head) { ListNode* prev = nullptr; ListNode* curr = head;
while (curr) { ListNode* next = curr->next; curr->next = prev; prev = curr; curr = next; } return prev;}Solution (Python):
def reverse_list(head): prev = None curr = head while curr: next_temp = curr.next curr.next = prev prev = curr curr = next_temp return prevTime Complexity: O(n) | Space Complexity: O(1)
Problem: Merge two sorted linked lists.
Solution (C++):
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { ListNode dummy(0); ListNode* curr = &dummy;
while (l1 && l2) { if (l1->val < l2->val) { curr->next = l1; l1 = l1->next; } else { curr->next = l2; l2 = l2->next; } curr = curr->next; } curr->next = l1 ? l1 : l2; return dummy.next;}Time Complexity: O(n+m) | Space Complexity: O(1)
Problem: Find maximum depth of binary tree.
Solution (C++):
int maxDepth(TreeNode* root) { if (!root) return 0; return 1 + max(maxDepth(root->left), maxDepth(root->right));}Solution (Python):
def max_depth(root): if not root: return 0 return 1 + max(max_depth(root.left), max_depth(root.right))Time Complexity: O(n) | Space Complexity: O(h)
Problem: Find length of longest substring without repeating characters.
Example:
Input: "abcabcbb"Output: 3 (substring "abc")Solution (C++):
int lengthOfLongestSubstring(string s) { unordered_map<char, int> seen; int maxLen = 0, left = 0;
for (int right = 0; right < s.length(); right++) { if (seen.count(s[right]) && seen[s[right]] >= left) { left = seen[s[right]] + 1; } seen[s[right]] = right; maxLen = max(maxLen, right - left + 1); } return maxLen;}Solution (Python):
def length_of_longest_substring(s): seen = {} max_len = left = 0 for right, char in enumerate(s): if char in seen and seen[char] >= left: left = seen[char] + 1 seen[char] = right max_len = max(max_len, right - left + 1) return max_lenTime Complexity: O(n) | Space Complexity: O(min(m,n))
Problem: Find the maximum path sum in a binary tree.
Solution (C++):
class Solution { int maxSum = INT_MIN;public: int maxPathSum(TreeNode* root) { maxGain(root); return maxSum; }
int maxGain(TreeNode* node) { if (!node) return 0; int left = max(0, maxGain(node->left)); int right = max(0, maxGain(node->right)); maxSum = max(maxSum, node->val + left + right); return node->val + max(left, right); }};Solution (Python):
def max_path_sum(root): max_sum = float('-inf')
def max_gain(node): nonlocal max_sum if not node: return 0 left = max(0, max_gain(node.left)) right = max(0, max_gain(node.right)) max_sum = max(max_sum, node.val + left + right) return node.val + max(left, right)
max_gain(root) return max_sumTime Complexity: O(n) | Space Complexity: O(h)
Problem: Find all unique triplets that sum to zero.
Example:
Input: [-1,0,1,2,-1,-4]Output: [[-1,-1,2],[-1,0,1]]Solution (C++):
vector<vector<int>> threeSum(vector<int>& nums) { sort(nums.begin(), nums.end()); vector<vector<int>> result;
for (int i = 0; i < nums.size() - 2; i++) { if (i > 0 && nums[i] == nums[i-1]) continue;
int left = i + 1, right = nums.size() - 1; while (left < right) { int sum = nums[i] + nums[left] + nums[right]; if (sum == 0) { result.push_back({nums[i], nums[left], nums[right]}); while (left < right && nums[left] == nums[left+1]) left++; while (left < right && nums[right] == nums[right-1]) right--; left++; right--; } else if (sum < 0) { left++; } else { right--; } } } return result;}Time Complexity: O(n²) | Space Complexity: O(1)
Problem: Design LRU cache with O(1) get and put operations.
Solution (C++):
class LRUCache { int capacity; list<pair<int, int>> lru; unordered_map<int, list<pair<int, int>>::iterator> cache;public: LRUCache(int cap) : capacity(cap) {}
int get(int key) { if (!cache.count(key)) return -1; lru.splice(lru.begin(), lru, cache[key]); return cache[key]->second; }
void put(int key, int value) { if (cache.count(key)) { cache[key]->second = value; lru.splice(lru.begin(), lru, cache[key]); } else { if (cache.size() == capacity) { cache.erase(lru.back().first); lru.pop_back(); } lru.emplace_front(key, value); cache[key] = lru.begin(); } }};Solution (Python):
from collections import OrderedDict
class LRUCache: def __init__(self, capacity): self.cache = OrderedDict() self.capacity = capacity
def get(self, key): if key not in self.cache: return -1 self.cache.move_to_end(key) return self.cache[key]
def put(self, key, value): if key in self.cache: self.cache.move_to_end(key) self.cache[key] = value if len(self.cache) > self.capacity: self.cache.popitem(last=False)Time Complexity: O(1) for both | Space Complexity: O(capacity)
Problem: Determine if binary tree is a valid BST.
Solution (C++):
bool isValidBST(TreeNode* root) { return validate(root, LLONG_MIN, LLONG_MAX);}
bool validate(TreeNode* node, long long minVal, long long maxVal) { if (!node) return true; if (node->val <= minVal || node->val >= maxVal) return false; return validate(node->left, minVal, node->val) && validate(node->right, node->val, maxVal);}Solution (Python):
def is_valid_bst(root): def validate(node, min_val, max_val): if not node: return True if node.val <= min_val or node.val >= max_val: return False return validate(node.left, min_val, node.val) and \ validate(node.right, node.val, max_val) return validate(root, float('-inf'), float('inf'))Time Complexity: O(n) | Space Complexity: O(h)
Problem: Count number of islands in a 2D grid.
Solution (C++):
int numIslands(vector<vector<char>>& grid) { int count = 0; for (int i = 0; i < grid.size(); i++) { for (int j = 0; j < grid[0].size(); j++) { if (grid[i][j] == '1') { dfs(grid, i, j); count++; } } } return count;}
void dfs(vector<vector<char>>& grid, int i, int j) { if (i < 0 || i >= grid.size() || j < 0 || j >= grid[0].size() || grid[i][j] == '0') return; grid[i][j] = '0'; dfs(grid, i+1, j); dfs(grid, i-1, j); dfs(grid, i, j+1); dfs(grid, i, j-1);}Time Complexity: O(m×n) | Space Complexity: O(m×n)
Problem: Determine if you can finish all courses given prerequisites.
Solution (C++):
bool canFinish(int numCourses, vector<vector<int>>& prerequisites) { vector<vector<int>> graph(numCourses); vector<int> inDegree(numCourses, 0);
for (auto& p : prerequisites) { graph[p[1]].push_back(p[0]); inDegree[p[0]]++; }
queue<int> q; for (int i = 0; i < numCourses; i++) { if (inDegree[i] == 0) q.push(i); }
int count = 0; while (!q.empty()) { int course = q.front(); q.pop(); count++; for (int next : graph[course]) { if (--inDegree[next] == 0) q.push(next); } }
return count == numCourses;}Time Complexity: O(V+E) | Space Complexity: O(V+E)
Problem: Find median with O(log(min(m,n))) complexity.
Solution (C++):
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { if (nums1.size() > nums2.size()) swap(nums1, nums2);
int m = nums1.size(), n = nums2.size(); int low = 0, high = m;
while (low <= high) { int i = (low + high) / 2; int j = (m + n + 1) / 2 - i;
int maxLeft1 = (i == 0) ? INT_MIN : nums1[i-1]; int minRight1 = (i == m) ? INT_MAX : nums1[i]; int maxLeft2 = (j == 0) ? INT_MIN : nums2[j-1]; int minRight2 = (j == n) ? INT_MAX : nums2[j];
if (maxLeft1 <= minRight2 && maxLeft2 <= minRight1) { if ((m + n) % 2 == 0) { return (max(maxLeft1, maxLeft2) + min(minRight1, minRight2)) / 2.0; } return max(maxLeft1, maxLeft2); } else if (maxLeft1 > minRight2) high = i - 1; else low = i + 1; } return 0.0;}Time Complexity: O(log(min(m,n))) | Space Complexity: O(1)
Problem: Merge k sorted linked lists.
Solution (C++):
ListNode* mergeKLists(vector<ListNode*>& lists) { auto cmp = [](ListNode* a, ListNode* b) { return a->val > b->val; }; priority_queue<ListNode*, vector<ListNode*>, decltype(cmp)> pq(cmp);
for (auto node : lists) { if (node) pq.push(node); }
ListNode dummy(0); ListNode* curr = &dummy;
while (!pq.empty()) { curr->next = pq.top(); pq.pop(); curr = curr->next; if (curr->next) pq.push(curr->next); }
return dummy.next;}Time Complexity: O(N log k) | Space Complexity: O(k)
Problem: Calculate water trapped after raining.
Example:
Input: [0,1,0,2,1,0,1,3,2,1,2,1]Output: 6Solution (C++):
int trap(vector<int>& height) { int left = 0, right = height.size() - 1; int leftMax = 0, rightMax = 0; int water = 0;
while (left < right) { if (height[left] < height[right]) { if (height[left] >= leftMax) { leftMax = height[left]; } else { water += leftMax - height[left]; } left++; } else { if (height[right] >= rightMax) { rightMax = height[right]; } else { water += rightMax - height[right]; } right--; } } return water;}Time Complexity: O(n) | Space Complexity: O(1)
Problem: Find all possible sentences from word dictionary.
Solution (C++):
vector<string> wordBreak(string s, vector<string>& wordDict) { unordered_set<string> dict(wordDict.begin(), wordDict.end()); unordered_map<int, vector<string>> memo; return helper(s, 0, dict, memo);}
vector<string> helper(string& s, int start, unordered_set<string>& dict, unordered_map<int, vector<string>>& memo) { if (memo.count(start)) return memo[start]; if (start == s.length()) return {""};
vector<string> result; for (int end = start + 1; end <= s.length(); end++) { string word = s.substr(start, end - start); if (dict.count(word)) { auto rest = helper(s, end, dict, memo); for (auto& r : rest) { result.push_back(word + (r.empty() ? "" : " " + r)); } } } return memo[start] = result;}Time Complexity: O(n × 2^n) | Space Complexity: O(n × 2^n)
Problem: Design algorithm to serialize/deserialize binary tree.
Solution (C++):
class Codec {public: string serialize(TreeNode* root) { if (!root) return "null,"; return to_string(root->val) + "," + serialize(root->left) + serialize(root->right); }
TreeNode* deserialize(string data) { queue<string> nodes; string token; for (char c : data) { if (c == ',') { nodes.push(token); token.clear(); } else { token += c; } } return build(nodes); }
private: TreeNode* build(queue<string>& nodes) { string val = nodes.front(); nodes.pop(); if (val == "null") return nullptr; TreeNode* node = new TreeNode(stoi(val)); node->left = build(nodes); node->right = build(nodes); return node; }};Time Complexity: O(n) | Space Complexity: O(n)
Master DSA fundamentals
Focus on optimization
Time management
Common patterns
Microsoft 2024 papers
Previous year papers with coding questions
Microsoft 2025 papers
Latest papers with current year questions
Microsoft interview experience
Real interview experiences
Microsoft preparation guide
Comprehensive preparation strategy
Microsoft main page
Complete Microsoft placement guide
Google · Amazon · Meta · TCS · Infosys · Wipro
Practice Microsoft coding questions regularly! Focus on medium-hard DSA problems. Microsoft values optimal solutions and clean code.
Pro Tip: Microsoft interviews emphasize problem-solving approach. Think out loud and communicate your thought process clearly.