Importance of Coding in Placements
The coding round in placements cannot be ignored. Coding assessments are one of the primary methods for evaluating candidates' problem-solving skills, logical thinking, and technical knowledge. Most companies prefer candidates who excel in coding round questions for placement because it demonstrates their ability to work under pressure and their proficiency in programming concepts.
The coding problems are tested for job placement, and practicing regularly ensures that you can tackle a wide range of problems. These coding tests are designed to test your understanding of basic programming questions for placement, data structures and algorithms (DSA), and even advanced topics like dynamic programming and graph theory.
Types of Coding Questions for 2025
In 2025, the types of coding questions asked by companies during technical interviews are evolving with the increasing demand for problem-solving. Here’s a breakdown of the types of coding questions asked in companies:
Google Interview Coding Questions
- Remove Duplicate Elements from Sorted Array
- Longest Common Prefix in an Array
- Modular Exponentiation (Power in Modular Arithmetic)
- Subarray with Given Sum
- Find Triplets with Zero Sum
- Jumping Numbers
- Implement LRU Cache
- Maximum Rectangular Area in a Histogram
- Sorted Linked List to BST
- Longest Valid Parentheses
Facebook Interview Coding Questions
- Find All Pairs with a Given Sum
- Minimum Depth of a Binary Tree
- K-Palindrome
- Find All Pairs with a Given Sum (Duplicate?)
- Subarray with Given Sum
- Word Boggle
- Stock Buy and Sell II
- Maximum Path Sum between Two Special Nodes
- Maximum Rectangular Area in a Histogram
Amazon Interview Coding Questions
- Implement a Stack with Push(), Pop() and Min() in O(1) Time
- Level Order Traversal
- Equal Point in a String of Brackets
- Add Two Numbers Represented by Linked Lists
- Maximum of All Subarrays of Size K
- Implement LRU Cache
- Smallest Window in a String Containing All Characters of Another String
Microsoft Interview Coding Questions
- Missing Number in Array
- Reverse a Linked List
- Root to Leaf Path Sum
- Kadane’s Algorithm
- Majority Element
- Coin Change
- Max Circular Subarray Sum
- Travelling Salesman Problem
Adobe Interview Coding Questions
- Reverse Words in a Given String
- Root to Leaf Path Sum
- Level Order Traversal in Spiral Form
- Search in a Rotated Array
- Subset Sum Problem
- Merge Sort for Linked List
- Merge Without Extra Space
- Number of Distinct Words with K Maximum Contiguous Vowels
Oracle Interview Coding Questions
- Search in a Matrix
- Power of 2
- 0 - 1 Knapsack Problem
- Kadane’s Algorithm
- Heap Sort
- Solve the Sudoku
- Redundant Parenthesis
- AVL Tree Deletion
Walmart Interview Coding Questions
- Count All Possible Paths from Top Left to Bottom Right
- Longest Consecutive Subsequence
- Largest Number in K Swaps
- Word Break
- Alien Dictionary
- Implement LRU Cache
- Wildcard Pattern Matching
Cisco Interview Coding Questions
- Missing Number in Array
- Reverse Words in a Given String
- Count Set Bits
- Swap Two Nibbles in a Byte
- Permutations of a Given String
- Level Order Traversal
- ZigZag Tree Traversal
- Negative Weight Cycle
- Goldbach Conjecture
Qualcomm Interview Coding Questions
- Find Length of Loop
- Reverse a Linked List
- Array Subset of Another Array
- Find Prime Numbers in a Range
- Sort 0s, 1s, and 2s
- Merge Sort
- Next Permutation
- Find Prime Numbers in a Range
IBM Interview Coding Questions
- Leaders in an Array
- Pattern Searching
- Missing Number in Array
- First Non-Repeating Character in a Stream
- Kadane’s Algorithm
- Flattening a Linked List
- Count Possible Ways to Construct Buildings
- Tree Boundary Traversal
Accenture Interview Coding Questions
- Missing in Array
- Alternate Positive and Negative Numbers
- Count Special Numbers
- Search in a Rotated Array
- Heap Sort
- Max Rectangle
- Boolean Parenthesization
Most Asked Coding Questions for Placement Hiring 2025
Candidates can expect these types of coding questions for their placement hiring. Here are the top 15 coding questions with solutions in C++:
Problem 1: Identify the missing number in an array with n-1 numbers.
#include <iostream>
#include <vector>
using namespace std;
int findMissingNumber(vector<int>& nums) {
int n = nums.size() + 1;
int total_sum = n * (n + 1) / 2;
int array_sum = 0;
for (int num : nums) {
array_sum += num;
}
return total_sum - array_sum;
}
int main() {
vector<int> nums = {1, 2, 4, 6, 3, 7, 8};
cout << "Missing Number: " << findMissingNumber(nums) << endl;
return 0;
}
Output:
Missing Number: 5
Problem 2: Given an array of integers and a target number, find the two numbers that sum up to the target.
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
vector<int> twoSum(const 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 {};
}
int main() {
vector<int> nums = {2, 7, 11, 15};
int target = 9;
vector<int> result = twoSum(nums, target);
cout << "Indices: " << result[0] << ", " << result[1] << endl;
return 0;
}
Output
Indices: 0, 1
Problem 3: Calculate the longest substring without repeating characters.
#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;
int lengthOfLongestSubstring(string s) {
unordered_map<char, int> map;
int left = 0, max_len = 0;
for (int right = 0; right < s.length(); ++right) {if (map.find(s[right]) != map.end()) {
left = max(left, map[s[right]] + 1);
}
map[s[right]] = right;
max_len = max(max_len, right - left + 1);
}
return max_len;
}
int main() {
string s = "abcabcbb";
cout << "Length of Longest Substring: " << lengthOfLongestSubstring(s) << endl;
return 0;
}
Output
Length of Longest Substring: 3
Problem 4: Merge two sorted arrays into a single sorted array.
#include <stdio.h>
void mergeArrays(int arr1[], int arr2[], int n1, int n2, int result[]) {
int i = 0, j = 0, k = 0;
while (i < n1 && j < n2) {
if (arr1[i] < arr2[j]) {
result[k++] = arr1[i++];
} else {
result[k++] = arr2[j++];
}
}
while (i < n1) {
result[k++] = arr1[i++];
}
while (j < n2) {
result[k++] = arr2[j++];
}
}
int main() {
int arr1[] = {1, 3, 5, 7};
int arr2[] = {2, 4, 6, 8};
int result[8];
mergeArrays(arr1, arr2, 4, 4, result);
printf("Merged Array: ");
for (int i = 0; i < 8; i++) {
printf("%d ", result[i]);
}
printf("\n");
return 0;
}
Output
Merged Array: 1 2 3 4 5 6 7 8
Problem 5: Implement binary search on a sorted array.
#include <iostream>
#include <vector>
using namespace std;
int binarySearch(const vector<int>& arr, int target) {
int left = 0, right = arr.size() - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (arr[mid] == target) {
return mid;
}
if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return -1;
}
int main() {
vector<int> arr = {1, 3, 5, 7, 9, 11, 13};
int target = 7;
int result = binarySearch(arr, target);
if (result != -1) {
cout << "Element found at index " << result << endl;
} else {
cout << "Element not found" << endl;
}
return 0;
}
Output
Element found at index 3
Problem 6: Find the largest sum of non-adjacent numbers in an array.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int largestSumNonAdjacent(const vector<int>& nums) {
int include = 0, exclude = 0;
for (int num : nums) {
int new_exclude = max(include, exclude);
include = exclude + num;
exclude = new_exclude;
}
return max(include, exclude);
}
int main() {
vector<int> nums = {2, 4, 6, 2, 5};
cout << "Largest Sum of Non-Adjacent Numbers: " << largestSumNonAdjacent(nums) << endl;
return 0;
}
Output
Largest Sum of Non-Adjacent Numbers: 10
₹ 49,000
Karthik was able to transform his career from a boring job to an
exciting job in software!
Talk to a career expert
Problem 7: Find the Kth largest element in an unsorted array.
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int findKthLargest(vector<int>& nums, int k) {
priority_queue<int, vector<int>, greater<int>> minHeap;
for (int num : nums) {
minHeap.push(num);
if (minHeap.size() > k) {
minHeap.pop();
}
}
return minHeap.top();
}
int main() {
vector<int> nums = {3, 2, 1, 5, 6, 4};
int k = 2;
cout << "Kth largest element is: " << findKthLargest(nums, k) << endl;
return 0;
}
Output
Kth largest element is: 5
Problem 8: Count the number of inversions in an array, where an inversion is a pair (i, j) such that i < j and arr[i] > arr[j].
#include <iostream>
#include <vector>
using namespace std;
int mergeAndCount(vector<int>& arr, vector<int>& temp, int left, int right) {
if (left == right) return 0;
int mid = left + (right - left) / 2;
int inv_count = mergeAndCount(arr, temp, left, mid);
inv_count += mergeAndCount(arr, temp, mid + 1, right);
inv_count += merge(arr, temp, left, mid, right);
return inv_count;
}
int merge(vector<int>& arr, vector<int>& temp, int left, int mid, intright) {
int i = left, j = mid + 1, k = left, inv_count = 0;
while (i <= mid && j <= right) {
if (arr[i] <= arr[j]) {
temp[k++] = arr[i++];
} else {
temp[k++] = arr[j++];
inv_count += (mid - i + 1);
}
}
while (i <= mid) temp[k++] = arr[i++];
while (j <= right) temp[k++] = arr[j++];
for (i = left; i <= right; i++) arr[i] = temp[i];
return inv_count;
}
int main() {
vector<int> arr = {1, 20, 6, 4, 5};
vector<int> temp(arr.size());
cout << "Number of inversions: " << mergeAndCount(arr, temp, 0, arr.size() - 1) << endl;
return 0;
}
Output
Number of inversions: 5
Problem 9: Find a peak element in an array. An element is a peak if it is greater than or equal to its neighbours.
#include <iostream>
#include <vector>
using namespace std;
int findPeakElement(vector<int>& nums) {
int left = 0, right = nums.size() - 1;
while (left < right) {
int mid = left + (right - left) / 2;
if (nums[mid] > nums[mid + 1]) {
right = mid;
} else {
left = mid + 1;
}
}
return left;
}
int main() {
vector<int> nums = {1, 2, 3, 1};
cout << "Peak Element: " << findPeakElement(nums) << endl;
return 0;
}
Output
Peak Element: 2
Problem 10: Given two strings s and p, find all the start indices of p's anagrams in s.
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
vector<int> findAnagrams(string s, string p) {
vector<int> result;
if (s.size() < p.size()) return result;
unordered_map<char, int> p_map, s_map;
for (char c : p) p_map[c]++;
for (int i = 0; i < p.size(); ++i) s_map[s[i]]++;
if (p_map == s_map) result.push_back(0);
for (int i = p.size(); i < s.size(); ++i) {
s_map[s[i]]++;
s_map[s[i - p.size()]]--;
if (s_map[s[i - p.size()]] == 0) {
s_map.erase(s[i - p.size()]);
}
if (p_map == s_map) result.push_back(i - p.size() + 1);
}
return result;
}
int main() {
string s = "cbaebabacd", p = "abc";
vector<int> result = findAnagrams(s, p);
cout << "Anagram Indices: ";
for (int index : result) {
cout << index << " ";
}
cout << endl;
return 0;
}
Output
Anagram Indices: 0 6
Problem 11: In a grid of oranges, some are rotten and some are fresh. Each minute, any fresh orange that is adjacent to a rotten one becomes rotten. Return the minimum number of minutes that must elapse before no fresh oranges remain.
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int orangesRotting(vector<vector<int>>& grid) {
int fresh = 0, minutes = 0;
queue<pair<int, int>> q;
for (int i = 0; i < grid.size(); ++i) {
for (int j = 0; j < grid[0].size(); ++j) {
if (grid[i][j] == 1) fresh++;
if (grid[i][j] == 2) q.push({i, j});
}
}
if (fresh == 0) return 0;
vector<vector<int>> directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
while (!q.empty()) {
int size = q.size();
bool rot = false;
for (int i = 0; i < size; ++i) {
auto [x, y] = q.front();
q.pop();
for (auto& dir : directions) {
int nx = x + dir[0], ny = y + dir[1];
if (nx >= 0 && ny >= 0 && nx < grid.size() && ny < grid[0].size() && grid[nx][ny] == 1) {
grid[nx][ny] = 2;
fresh--;
rot = true;
q.push({nx, ny});
}
}
}
if (rot) minutes++;
}
return fresh == 0 ? minutes : -1;
}
int main() {
vector<vector<int>> grid = {{2, 1, 1}, {1, 1, 0}, {0, 1, 1}};
cout << "Minutes to rot all oranges: " << orangesRotting(grid) << endl;
return 0;
}
Output
Minutes to rot all oranges: 4
Problem 12: Check whether a string has balanced parentheses.
#include <iostream>
#include <stack>
using namespace std;
bool isValid(string s) {
stack<char> stk;
for (char c : s) {
if (c == '(' || c == '{' || c == '[') {
stk.push(c);
} else {
if (stk.empty()) return false;
char top = stk.top();
if ((c == ')' && top == '(') || (c == '}' && top == '{') || (c == ']' && top == '[')) {
stk.pop();
} else {
return false;
}
}
}
return stk.empty();
}
int main() {
string s = "({[]})";
cout << "Balanced Parentheses: " << isValid(s) << endl;
return 0;
}
Output
Balanced Parentheses: 1
Problem 13: Count the number of prime numbers less than a given number n.
#include <iostream>
#include <vector>
using namespace std;
int countPrimes(int n) {
if (n <= 2) return 0;
vector<bool> isPrime(n, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i * i < n; ++i) {
if (isPrime[i]) {
for (int j = i * i; j < n; j += i) {
isPrime[j] = false;
}
}
}
int count = 0;
for (int i = 2; i < n; ++i) {
if (isPrime[i]) count++;
}
return count;
}
int main() {
int n = 10;
cout << "Number of primes less than " << n << ": " << countPrimes(n) << endl;
return 0;
}
Output
Number of primes less than 10: 4
Problem 14: Find the next lexicographical permutation of a given list of numbers.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void nextPermutation(vector<int>& nums) {
int i = nums.size() - 2;
while (i >= 0 && nums[i] >= nums[i + 1]) {
--i;
}
if (i >= 0) {
int j = nums.size() - 1; while (nums[j] <= nums[i]) {
--j;
}
swap(nums[i], nums[j]);
}
reverse(nums.begin() + i + 1, nums.end());
}
int main() {
vector<int> nums = {1, 2, 3};
nextPermutation(nums);
cout << "Next Permutation: ";
for (int num : nums) {
cout << num << " ";
}
cout << endl;
return 0;
}
Output
Next Permutation: 1 3 2
Problem 15: Print the nth Fibonacci number using dynamic programming.
#include <iostream>
#include <vector>
using namespace std;
int fib(int n) {
if (n <= 1) return n;
vector<int> dp(n + 1, 0);
dp[1] = 1;
for (int i = 2; i <= n; ++i) {
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n];
}
int main() {
int n = 6;
cout << "Fibonacci number: " << fib(n) << endl;
return 0;
}
Output:
Fibonacci number: 8
Mock Interviews and Preparation Strategy
Mock interviews are essential for interview preparation, allowing you to practice real-world scenarios, improve communication, and boost confidence. Here's an effective strategy:
- Begin mock interviews at least 2-3 weeks before the actual interview. Your weaknesses can then be worked on during this time.
- Try to maintain the actual interview environment such as dressing professionally, being precise with your answers, and avoiding distractions.
- After each mock interview, seek constructive feedback on your answers, body language, and overall presentation.
- Focus on frequently asked questions in your field. Practice your responses out loud.
- Sharpen core competencies relevant to the role. Learn about company-specific knowledge and industry trends.
- Go over your resume, key projects, and the job description.
- Quickly practice answers for technical or behavioral questions.
- Relax before the interview; do a quick breathing exercise or visualize success.
- Mock interviews and strategic last-minute preparation will ensure you're ready and confident for the real interview.
Conclusion
In conclusion, learning coding is crucial for placement success, as it assesses problem-solving, logic, and technical skills. In 2025, companies like Google, Amazon, and Microsoft focuses on their specific needs, requiring candidates to understand their unique expectations. Preparing through mock interviews, coding practice, and focusing on common patterns is essential. Strategic mock interviews will greatly improve your chances of excelling in placement coding rounds.
₹ 49,000
Karthik was able to transform his career from a boring job to an
exciting job in software!
Talk to a career expert
Frequently Asked Questions
1. What are the common coding questions for placements?
Common coding questions for placement include concepts related to arrays, strings, sorting, searching, recursion, dynamic programming, and graphs.
2. How can I prepare for coding rounds in campus placements?
To prepare for campus placement coding questions, focus on mastering DSA questions for placement, practicing regularly, and using resources like Codechef and LeetCode.