- Overview of Accenture Coding Round
- Breakdown of Accenture Coding Questions
- Top 5 Best MCQs for Accenture Coding Test
- Preparation Tips for Accenture Coding Round
- Conclusion
- Frequently Asked Questions (FAQs)
Accenture Coding Questions: 5 Coding Solutions for Freshers 2025
Accenture is one of the world’s leading consulting and technology services firms. For fresh graduates aspiring to join Accenture, preparing for the coding round is crucial as it tests your technical prowess, problem-solving ability, and coding skills.
In this guide, we’ll break down the important aspects of Accenture’s coding questions, focusing on key areas like coding, pseudo code, and problem-solving techniques, helping you prepare effectively for the coding round. We’ll also explore the previous year's coding questions and share valuable tips to crack the exam.
Overview of Accenture Coding Round
Accenture’s coding round typically involves solving a series of technical problems within a limited time frame. The questions generally test your proficiency in data structures, algorithms, and logical problem-solving. Here's a breakdown of the Accenture coding round structure:
|
Section |
Topics Covered |
Focus Area |
Recommended Preparation Time |
|
Problem-Solving |
Arrays, Strings, Searching, Sorting |
Tests basic algorithm skills and how you approach problems |
2-3 hours per day |
|
Data Structures |
Linked List, Stack, Queue, Trees |
Tests knowledge of fundamental data structures and their usage |
3-4 hours per day |
|
Algorithms |
Sorting, Recursion, Dynamic Programming |
Evaluates problem-solving approaches to complex algorithms |
3-4 hours per week |
|
Pseudo Code |
Problem Representation in Pseudocode |
Measures ability to logically represent solutions to problems |
1-2 hours per day |
Breakdown of Accenture Coding Questions
Accenture Coding Questions
Accenture’s coding questions typically consist of problems that require you to write code that solves real-world challenges. The types of questions you might encounter include:
|
Type of Question |
Description |
Example Topics |
Tips |
|
Algorithmic Problems |
Solving problems using algorithms like sorting, searching |
Sorting Algorithms, Binary Search, Merge Sort |
Focus on time complexity and edge cases. |
|
Data Structure Problems |
Working with data structures like arrays, linked lists |
Arrays, Stacks, Queues, Trees |
Practice implementing and manipulating data structures. |
|
Mathematical Problems |
Applying mathematical logic to solve problems |
Prime Numbers, Fibonacci Series, Factorials |
Use math-based functions and optimise for efficiency. |
|
Logical Problems |
Using logic to create efficient solutions |
Puzzles, number sequences, or logical deductions |
Understand the core logic and optimise the solution. |
Are you preparing for the upcoming Accenture Coding test? Click here to access coding practice sessions from moderate to challenging levels.
Accenture Pseudo Code Questions
In pseudo-code questions, you’ll be asked to represent a solution in a human-readable format before implementing it in a programming language. The objective is to assess your logical thinking and ability to plan before coding.
|
Topic |
Description |
Example |
Tips |
|
Problem Decomposition |
Breaking down a problem into smaller, manageable steps |
Write pseudo code to find the factorial of a number. |
Use simple structures like loops, conditionals, and function calls. |
|
Flow Representation |
Representing the flow of the algorithm without syntax errors |
Write pseudo code to reverse a string. |
Ensure clarity in representation, focusing on logic over syntax. |
|
Time Complexity Analysis |
Analyzing the time complexity of an algorithm before coding |
Pseudo code for finding the sum of an array using recursion. |
Think about efficient solutions using Big O notation. |
Accenture Previous Year Coding Questions
Studying the previous year's coding questions is an excellent way to prepare for Accenture’s coding round. Here’s a summary of common topics:
|
Year |
Question Type |
Topics Tested |
Difficulty Level |
|
2023 |
Data Structures |
Arrays, Linked List |
Moderate |
|
2022 |
Algorithms and Math |
Sorting, Prime Numbers |
Moderate |
|
2021 |
Dynamic Programming |
Fibonacci Series, Factorial |
High |
|
2020 |
Recursion and Searching |
Binary Search, Recursion Problems |
Easy |
|
2019 |
Logical & Analytical Problems |
Puzzles, String Manipulation |
Easy to Moderate |
Top 5 Coding Problems with Solutions
Problem Statement 1
Vikas is starting to study math for his class 10 boards, because unfortunately everything went offline. He is currently studying circles and geometry. He is stuck on a particular problem, and needs your help.
You are given an array points where points[i] = [xi, yi] is the coordinates of the ith point on a 2D plane. Multiple points can have the same coordinates.
You are also given an array queries where queries[j] = [xj, yj, rj] describes a circle centered at (xj, yj) with a radius of rj.
For each query queries[j], compute the number of points inside the jth circle. Points on the border of the circle are considered inside.
Print an array answer, where answer[j] is the answer to the jth query.
Constraints:
- 1 <= points.length <= 500
- points[i].length == 2
- 0 <= xi, yi <= 500
- 1 <= queries.length <= 500
- queries[j].length == 3
- 0 <= xj, yj <= 500
- 1 <= rj <= 500
- All coordinates are integers.
Input format:
First line of the input contains integer n (length of first 2D Vector) no of coordinate points.
Second line contain 2n (x,y) space separated integer values of first vector.
Third line contain integer value m (length of second 2D Vector) no of queries
Fourth line contain 3m (x,y,r) space separated integer values of second vector.
Ex:
4
1 3 3 3 5 3 2 2
3
2 3 1 4 3 1 1 1 2
Output Format :
Print an array answer, where answer[j] is the answer to the jth query.
Solution C++
#include <bits/stdc++.h>
using namespace std;
int sqr(int a) {
return a * a;
}
int find_left_boundry_index(vector<vector > & points , int x_center , int y_center , int r) {
int lo = 0, hi = points.size();
while (lo < hi) {
int mi = lo + (hi - lo ) / 2;
if (x_center - r <= points[mi][0])
hi = mi;
else
lo = mi + 1;
}
return hi == points.size() or (points[hi][0] > x_center + r or points[hi][0] < x_center - r) ? points.size() : hi;
}
vector countPoints(vector<vector>& points, vector<vector>& queries) {
sort(points.begin(), points.end());
vector ans;
for (int i = 0; i < queries.size(); i++) {
int x_center = queries[i][0], y_center = queries[i][1], r = queries[i][2];
int index = find_left_boundry_index(points, x_center , y_center, r);
int count = 0;
for (int j = index; j < points.size() and points[j][0] <= x_center + r; j++) {
int x = points[j][0];
int y = points[j][1];
count += sqr(x_center - x) + sqr(y_center - y) <= r * r;
}
ans.push_back(count);
}
return ans;
}
int main() {
int m, n;
cin>>n;
vector<vector> points;
for(int i=0; i<n; i++){
vector temp(2);
for(int j=0; j<2; j++){
cin>>temp[j];
}
points.push_back(temp);
}
cin>>m;
vector<vector> queries;
for(int i=0; i<m; i++){
vector temp(3);
for(int j=0; j<3; j++){
cin>>temp[j];
}
queries.push_back(temp);
}
vector result;
result = countPoints(points, queries);
for(int i=0; i< m; i++){
cout<<result[i]<<" ";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiBpbnQgc3FyKGludCBhKSB7CiAgIHJldHVybiBhICogYTsKfQppbnQgZmluZF9sZWZ0X2JvdW5kcnlfaW5kZXgodmVjdG9yPHZlY3RvcjxpbnQ+ID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ICBpbnQgeCA9IHBvaW50c1tqXVswXTsKICAgICAgICAgICBpbnQgeSA9IHBvaW50c1tqXVsxXTsKICAgICAgICAgICBjb3VudCArPSBzcXIoeF9jZW50ZXIgLSB4KSArIHNxcih5X2NlbnRlciAtIHkpIDw9IHIgKiByOwogICAgICAgfQogICAgICAgYW5zLnB1c2hfYmFjayhjb3VudCk7CiAgIH0KICAgcmV0dXJuIGFuczsKfQppbnQgbWFpbigpIHsKICAgaW50IG0sIG47CiAgIGNpbj4+bjsKICAgdmVjdG9yPHZlY3RvcjxpbnQ+PiBwb2ludHM7CiAgIGZvcihpbnQgaT0wOyBpPG47IGkrKyl7CiAgICAgICB2ZWN0b3I8aW50PiB0ZW1wKDIpOwogICAgICAgZm9yKGludCBqPTA7IGo8MjsgaisrKXsKICAgICAgICAgICBjaW4+PnRlbXBbal07CiAgICAgICB9CiAgICAgICBwb2ludHMucHVzaF9iYWNrKHRlbXApOwogICB9CiAgIGNpbj4+bTsKICAgdmVjdG9yPHZlY3RvcjxpbnQ+PiBxdWVyaWVzOwogICBmb3IoaW50IGk9MDsgaTxtOyBpKyspewogICAgICAgdmVjdG9yPGludD4gdGVtcCgzKTsKICAgICAgIGZvcihpbnQgaj0wOyBqPDM7IGorKyl7CiAgICAgICAgICAgY2luPj50ZW1wW2pdOwogICAgICAgfQogICAgICAgcXVlcmllcy5wdXNoX2JhY2sodGVtcCk7CiAgIH0KICAgdmVjdG9yPGludD4gcmVzdWx0OwogICByZXN1bHQgPSBjb3VudFBvaW50cyhwb2ludHMsIHF1ZXJpZXMpOwogICBmb3IoaW50IGk9MDsgaTwgbTsgaSsrKXsKICAgICAgIGNvdXQ8PHJlc3VsdFtpXTw8IiAiOwogICB9CiAgIHJldHVybiAwOwp9Cg==
Solution Python
# Enter your code here. Read input from STDIN. Print output to STDdef sqr(a):
return a * a
def find_left_boundary_index(points, x_center, y_center, r):
lo, hi = 0, len(points)
while lo < hi:
mi = lo + (hi - lo) // 2
if x_center - r <= points[mi][0]:
hi = mi
else:
lo = mi + 1
return hi if hi < len(points) and x_center - r <= points[hi][0] <= x_center + r else len(points)
def countPoints(points, queries):
points.sort()
result = []
for query in queries:
x_center, y_center, r = query
index = find_left_boundary_index(points, x_center, y_center, r)
count = 0
for j in range(index, len(points)):
if points[j][0] > x_center + r:
break
x, y = points[j]
if sqr(x_center - x) + sqr(y_center - y) <= r * r:
count += 1
result.append(count)
return result
def main():
import sys
input = sys.stdin.read
data = list(map(int, input().split()))
idx = 0
n = data[idx]
idx += 1
points = []
for _ in range(n):
points.append([data[idx], data[idx + 1]])
idx += 2
m = data[idx]
idx += 1
queries = []
for _ in range(m):
queries.append([data[idx], data[idx + 1], data[idx + 2]])
idx += 3
result = countPoints(points, queries)
print(' '.join(map(str, result)))
if __name__ == "__main__":
main()
IyBFbnRlciB5b3VyIGNvZGUgaGVyZS4gUmVhZCBpbnB1dCBmcm9tIFNURElOLiBQcmludCBvdXRwdXQgdG8gU1REZGVmIHNxcihhKToNCiAgIHJldHVybiBhICogYQ0KDQoNCmRlZiBmaW5kX2xlZnRfYm91bmRhcnlfaW5kZXgocG9pbnRzLCB4X2NlbnRlciwgeV9jZW50ZXIsIHIpOg0KICAgbG8sIGhpID0gMCwgbGVuKHBvaW50cykNCiAgIHdoaWxlIGxvIDwgaGk6DQogICAgICAgbWkgPSBsbyArIChoaSAtIGxvKSAvLyAyDQogICAgICAgaWYgeF9jZW50ZXIgLSByIDw9IHBvaW50c1ttaV1bMF06DQogICAgICAgICAgIGhpID0gbWkNCiAgICAgICBlbHNlOg0KICAgICAgICAgICBsbyA9IG1pICsgMQ0KICAgcmV0dXJuIGhpIGlmIGhpIDwgbGVuKHBvaW50cykgYW5kIHhfY2VudGVyIC0gciA8PSBwb2ludHNbaGldWzBdIDw9IHhfY2VudGVyICsgciBlbHNlIGxlbihwb2ludHMpDQoNCg0KZGVmIGNvdW50UG9pbnRzKHBvaW50cywgcXVlcmllcyk6DQogICBwb2ludHMuc29ydCgpDQogICByZXN1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gMl1dKQ0KICAgICAgIGlkeCArPSAzDQogIA0KICAgcmVzdWx0ID0gY291bnRQb2ludHMocG9pbnRzLCBxdWVyaWVzKQ0KICAgcHJpbnQoJyAnLmpvaW4obWFwKHN0ciwgcmVzdWx0KSkpDQoNCg0KaWYgX19uYW1lX18gPT0gIl9fbWFpbl9fIjoNCiAgIG1haW4oKQ==
Solution Java
import java.util.*;
public class CountPointsInCircles {
// Function to compute the square of a number
private static int sqr(int a) {
return a * a;
}
// Function to find the left boundary index for the binary search
private static int findLeftBoundaryIndex(List<int[]> points, int x_center, int y_center, int r) {
int lo = 0, hi = points.size();
while (lo < hi) {
int mi = lo + (hi - lo) / 2;
if (x_center - r <= points.get(mi)[0])
hi = mi;
else
lo = mi + 1;
}
return hi == points.size() || points.get(hi)[0] > x_center + r || points.get(hi)[0] < x_center - r ? points.size() : hi;
}
public static List countPoints(List<int[]> points, List<int[]> queries) {
points.sort(Comparator.comparingInt(a -> a[0]));
List ans = new ArrayList<>();
for (int[] query : queries) {
int x_center = query[0], y_center = query[1], r = query[2];
int index = findLeftBoundaryIndex(points, x_center, y_center, r);
int count = 0;
for (int j = index; j < points.size() && points.get(j)[0] <= x_center + r; j++) {
int x = points.get(j)[0];
int y = points.get(j)[1];
if (sqr(x_center - x) + sqr(y_center - y) <= r * r) {
count++;
}
}
ans.add(count);
}
return ans;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
List<int[]> points = new ArrayList<>();
for (int i = 0; i < n; i++) {
int[] temp = {scanner.nextInt(), scanner.nextInt()};
points.add(temp);
}
int m = scanner.nextInt();
List<int[]> queries = new ArrayList<>();
for (int i = 0; i < m; i++) {
int[] temp = {scanner.nextInt(), scanner.nextInt(), scanner.nextInt()};
queries.add(temp);
}
List result = countPoints(points, queries);
for (int count : result) {
System.out.print(count + " ");
}
scanner.close();
}
}
aW1wb3J0IGphdmEudXRpbC4qOwoKCnB1YmxpYyBjbGFzcyBDb3VudFBvaW50c0luQ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q8PigpOwoKCiAgICAgICBmb3IgKGludFtdIHF1ZXJ5IDogcXVlcmllcykgewogICAgICAgICAgIGludCB4X2NlbnRlciA9IHF1ZXJ5WzBdLCB5X2NlbnRlciA9IHF1ZXJ5WzFdLCByID0gcXVlcnlbMl07CiAgICAgICAgICAgaW50IGluZGV4ID0gZmluZExlZnRCb3VuZGFyeUluZGV4KHBvaW50cywgeF9jZW50ZXIsIHlfY2VudGVyLCByKTsKICAgICAgICAgICBpbnQgY291bnQgPSAwOwoKCiAgICAgICAgICAgZm9yIChpbnQgaiA9IGluZGV4OyBqIDwgcG9pbnRzLnNpemUoKSAmJiBwb2ludHMuZ2V0KGopWzBdIDw9IHhfY2VudGVyICsgcjsgaisrKSB7CiAgICAgICAgICAgICAgIGludCB4ID0gcG9pbnRzLmdldChqKVswXTsKICAgICAgICAgICAgICAgaW50IHkgPSBwb2ludHMuZ2V0KGopWzFdOwogICAgICAgICAgICAgICBpZiAoc3FyKHhfY2VudGVyIC0geCkgKyBzcXIoeV9jZW50ZXIgLSB5KSA8PSByICogcikgewogICAgICAgICAgICAgICAgICAgY291bnQrKzsKICAgICAgICAgICAgICAgfQogICAgICAgICAgIH0KICAgICAgICAgICBhbnMuYWRkKGNvdW50KTsKICAgICAgIH0KICAgICAgIHJldHVybiBhbnM7CiAgIH0KCgogICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICBTY2FubmVyIHNjYW5uZXIgPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwoKCiAgICAgICBpbnQgbiA9IHNjYW5uZXIubmV4dEludCgpOwogICAgICAgTGlzdDxpbnRbXT4gcG9pbnRzID0gbmV3IEFycmF5TGlzdDw+KCk7CiAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgICAgIGludFtdIHRlbXAgPSB7c2Nhbm5lci5uZXh0SW50KCksIHNjYW5uZXIubmV4dEludCgpfTsKICAgICAgICAgICBwb2ludHMuYWRkKHRlbXApOwogICAgICAgfQoKCiAgICAgICBpbnQgbSA9IHNjYW5uZXIubmV4dEludCgpOwogICAgICAgTGlzdDxpbnRbXT4gcXVlcmllcyA9IG5ldyBBcnJheUxpc3Q8PigpOwogICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyBpKyspIHsKICAgICAgICAgICBpbnRbXSB0ZW1wID0ge3NjYW5uZXIubmV4dEludCgpLCBzY2FubmVyLm5leHRJbnQoKSwgc2Nhbm5lci5uZXh0SW50KCl9OwogICAgICAgICAgIHF1ZXJpZXMuYWRkKHRlbXApOwogICAgICAgfQoKCiAgICAgICBMaXN0PEludGVnZXI+IHJlc3VsdCA9IGNvdW50UG9pbnRzKHBvaW50cywgcXVlcmllcyk7CiAgICAgICBmb3IgKGludCBjb3VudCA6IHJlc3VsdCkgewogICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnQoY291bnQgKyAiICIpOwogICAgICAgfQogICAgICAgc2Nhbm5lci5jbG9zZSgpOwogICB9Cn0K
Problem Statement 2
There are N employees in a company, each with a certain power level represented in a sorted array pow of size N. Each employee has been assigned a message, and they need to pass this message to the next employee under the following conditions:
If Employee A passes a message to Employee B, then Employee B can only pass that message to Employee C if and only if the difference in power between A and B is equal to the difference in power between B and C.
Your task is to determine the maximum number of employees that can be part of a continuous message-passing sequence under these conditions.
Constraints :
1 <= N <= 10^3
1 <= pow[i] <= 10^4
Input Format :
The first line of input contains a single integer N representing the number of employees.
The second line of input contains N space-separated integers representing the power levels of the employees in a sorted array pow.
Output Format:
Print the maximum number of employees that can pass the same message in a sequence.
Solution C++
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll solve(vectora)
{
ll n = a.size();
if (n <= 2) // returning n if n is less than or equal to 2
return n;
ll max_len = 2;
ll dp[n]; // initializing dp
for (ll i = 0; i < n; i++) // making every element of dp as 2
{
dp[i] = 2;
}
for (ll j = n - 2; j >= 0; j--) // starting to iterate over the element
{
ll i = j - 1; // finding previous element of AP
ll k = j + 1; // finding next element of AP
while (i >= 0 && k < n) // iterating over the loop to check if A[i], A[j] and A[k] forms an AP or not
{
if (a[i] + a[k] == 2 * a[j]) // increment dp[j] if AP is formed
{
dp[j] = max(dp[k] + 1, dp[j]);
max_len = max(max_len, dp[j]);
i--;
k++;
}
else if (a[i] + a[k] < 2 * a[j]) // incrementing k
k++;
else // decrementing i
i--;
}
}
return max_len; // returning the ans
}
int main()
{
ll n;
cin>>n;
vectorvec(n);
for(ll i=0;i<n;i++)
{
cin>>vec[i];
}
cout << solve(vec);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcgaW50CgoKbGwgc29sdmUodmVjdG9yPGxsPmEpCnsKICAgbGwgbiA9IGEuc2l6ZSgpOwogICBpZiAobiA8PSAyKSAvLyByZXR1cm5pbmcgbiBpZiBuIGlzIGxlc3MgdGhhbiBvciBlcXVhbCB0byAyCiAgICAgICByZXR1cm4gbjsKCgogICBsbCBtYXhfbGVuID0gMjsKCgogICBsbCBkcFtuXTsgLy8gaW5pdGlhbGl6aW5nIGRwCgoKICAgZm9yIChsbCBpID0gMDsgaSA8IG47IGkrKykgLy8gbWFraW5nIGV2ZXJ5IGVsZW1lbnQgb2YgZHAgYXMgMgogICB7CiAgICAgICBkcFtpXSA9IDI7CiAgIH0KCgogICBmb3IgKGxsIGogPSBuIC0gMjsgaiA+PSAwOyBqLS0pIC8vIHN0YXJ0aW5nIHRvIGl0ZXJhdGUgb3ZlciB0aGUgZWxlbWVudAogICB7CiAgICAgICBsbCBpID0gaiAtIDE7IC8vIGZpbmRpbmcgcHJldmlvdXMgZWxlbWVudCBvZiBBUAogICAgICAgbGwgayA9IGogKyAxOyAvLyBmaW5kaW5nIG5leHQgZWxlbWVudCBvZiBBUAoKCiAgICAgICB3aGlsZSAoaSA+PSAwICYmIGsgPCBuKSAvLyBpdGVyYXRpbmcgb3ZlciB0aGUgbG9vcCB0byBjaGVjayBpZiBBW2ldLCBBW2pdIGFuZCBBW2tdIGZvcm1zIGFuIEFQIG9yIG5vdAogICAgICAgewogICAgICAgICAgIGlmIChhW2ldICsgYVtrXSA9PSAyICogYVtqXSkgLy8gaW5jcmVtZW50IGRwW2pdIGlmIEFQIGlzIGZvcm1lZAogICAgICAgICAgIHsKICAgICAgICAgICAgICAgZHBbal0gPSBtYXgoZHBba10gKyAxLCBkcFtqXSk7CiAgICAgICAgICAgICAgIG1heF9sZW4gPSBtYXgobWF4X2xlbiwgZHBbal0pOwogICAgICAgICAgICAgICBpLS07CiAgICAgICAgICAgICAgIGsrKzsKICAgICAgICAgICB9CiAgICAgICAgICAgZWxzZSBpZiAoYVtpXSArIGFba10gPCAyICogYVtqXSkgLy8gaW5jcmVtZW50aW5nIGsKICAgICAgICAgICAgICAgaysrOwogICAgICAgICAgIGVsc2UgLy8gZGVjcmVtZW50aW5nIGkKICAgICAgICAgICAgICAgaS0tOwogICAgICAgfQogICB9CiAgIHJldHVybiBtYXhfbGVuOyAvLyByZXR1cm5pbmcgdGhlIGFucwp9CgoKaW50IG1haW4oKQp7CiAgIGxsIG47CiAgIGNpbj4+bjsKICAgdmVjdG9yPGxsPnZlYyhuKTsKICAgZm9yKGxsIGk9MDtpPG47aSsrKQogICB7CiAgICAgICBjaW4+PnZlY1tpXTsKICAgfQogICBjb3V0IDw8IHNvbHZlKHZlYyk7CgoKICAgcmV0dXJuIDA7Cn0K
Solution Java
import java.util.Scanner;
import java.util.Vector;
public class Main {
public static long solve(Vector a) {
long n = a.size();
if (n <= 2) // returning n if n is less than or equal to 2
return n;
long max_len = 2;
long[] dp = new long[(int)n]; // initializing dp with 2
for (int i = 0; i < n; i++) // making every element of dp as 2
dp[i] = 2;
for (int j = (int)n - 2; j >= 0; j--) { // starting to iterate over the elements
int i = j - 1; // finding previous element of AP
int k = j + 1; // finding next element of AP
while (i >= 0 && k < n) { // iterating to check if a[i], a[j], a[k] form an AP
if (a.get(i) + a.get(k) == 2 * a.get(j)) { // increment dp[j] if AP is formed
dp[j] = Math.max(dp[k] + 1, dp[j]);
max_len = Math.max(max_len, dp[j]);
i--;
k++;
} else if (a.get(i) + a.get(k) < 2 * a.get(j)) // incrementing k
k++;
else // decrementing i
i--;
}
}
return max_len; // returning the answer
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
Vector vec = new Vector((int)n);
for (int i = 0; i < n; i++) {
vec.add(sc.nextLong());
}
System.out.println(solve(vec));
sc.close();
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwppbXBvcnQgamF2YS51dGlsLlZlY3RvcjsKCgpwdWJsaWMgY2xhc3MgTWFpbiB7CgoKICAgcHVibGljIHN0YXRpYyBsb25nIHNvbHZlKFZlY3RvcjxMb25nPiBhKSB7CiAgICAgICBsb25nIG4gPSBhLnNpemUoKTsKICAgICAgIGlmIChuIDw9IDIpICAvLyByZXR1cm5pbmcgbiBpZiBuIGlzIGxlc3MgdGhhbiBvciBlcXVhbCB0byAyCiAgICAgICAgICAgcmV0dXJuIG47CgoKICAgICAgIGxvbmcgbWF4X2xlbiA9IDI7CgoKICAgICAgIGxvbmdbXSBkcCA9IG5ldyBsb25nWyhpbnQpbl07ICAvLyBpbml0aWFsaXppbmcgZHAgd2l0aCAyCgoKICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSAgLy8gbWFraW5nIGV2ZXJ5IGVsZW1lbnQgb2YgZHAgYXMgMgogICAgICAgICAgIGRwW2ldID0gMjsKCgogICAgICAgZm9yIChpbnQgaiA9IChpbnQpbiAtIDI7IGogPj0gMDsgai0tKSB7ICAvLyBzdGFydGluZyB0byBpdGVyYXRlIG92ZXIgdGhlIGVsZW1lbnRzCiAgICAgICAgICAgaW50IGkgPSBqIC0gMTsgIC8vIGZpbmRpbmcgcHJldmlvdXMgZWxlbWVudCBvZiBBUAogICAgICAgICAgIGludCBrID0gaiArIDE7ICAvLyBmaW5kaW5nIG5leHQgZWxlbWVudCBvZiBBUAoKCiAgICAgICAgICAgd2hpbGUgKGkgPj0gMCAmJiBrIDwgbikgeyAgLy8gaXRlcmF0aW5nIHRvIGNoZWNrIGlmIGFbaV0sIGFbal0sIGFba10gZm9ybSBhbiBBUAogICAgICAgICAgICAgICBpZiAoYS5nZXQoaSkgKyBhLmdldChrKSA9PSAyICogYS5nZXQoaikpIHsgIC8vIGluY3JlbWVudCBkcFtqXSBpZiBBUCBpcyBmb3JtZWQKICAgICAgICAgICAgICAgICAgIGRwW2pdID0gTWF0aC5tYXgoZHBba10gKyAxLCBkcFtqXSk7CiAgICAgICAgICAgICAgICAgICBtYXhfbGVuID0gTWF0aC5tYXgobWF4X2xlbiwgZHBbal0pOwogICAgICAgICAgICAgICAgICAgaS0tOwogICAgICAgICAgICAgICAgICAgaysrOwogICAgICAgICAgICAgICB9IGVsc2UgaWYgKGEuZ2V0KGkpICsgYS5nZXQoaykgPCAyICogYS5nZXQoaikpICAvLyBpbmNyZW1lbnRpbmcgawogICAgICAgICAgICAgICAgICAgaysrOwogICAgICAgICAgICAgICBlbHNlICAvLyBkZWNyZW1lbnRpbmcgaQogICAgICAgICAgICAgICAgICAgaS0tOwogICAgICAgICAgIH0KICAgICAgIH0KCgogICAgICAgcmV0dXJuIG1heF9sZW47ICAvLyByZXR1cm5pbmcgdGhlIGFuc3dlcgogICB9CgoKICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgU2Nhbm5lciBzYyA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CiAgICAgICBsb25nIG4gPSBzYy5uZXh0TG9uZygpOwogICAgICAgVmVjdG9yPExvbmc+IHZlYyA9IG5ldyBWZWN0b3I8TG9uZz4oKGludCluKTsKCgogICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICB2ZWMuYWRkKHNjLm5leHRMb25nKCkpOwogICAgICAgfQoKCiAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oc29sdmUodmVjKSk7CiAgICAgICBzYy5jbG9zZSgpOwogICB9Cn0K
Solution Python
def solve(a):
n = len(a)
if n <= 2: # returning n if n is less than or equal to 2
return n
max_len = 2
dp = [2] * n # initializing dp with 2
for j in range(n - 2, -1, -1): # starting to iterate over the elements
i = j - 1 # finding previous element of AP
k = j + 1 # finding next element of AP
while i >= 0 and k < n: # iterating to check if a[i], a[j], a[k] form an AP
if a[i] + a[k] == 2 * a[j]: # increment dp[j] if AP is formed
dp[j] = max(dp[k] + 1, dp[j])
max_len = max(max_len, dp[j])
i -= 1
k += 1
elif a[i] + a[k] < 2 * a[j]: # incrementing k
k += 1
else: # decrementing i
i -= 1
return max_len # returning the answer
if __name__ == "__main__":
n = int(input())
vec = list(map(int, input().split()))
print(solve(vec))
ZGVmIHNvbHZlKGEpOg0KICAgbiA9IGxlbihhKQ0KICAgaWYgbiA8PSAyOiAgIyByZXR1cm5pbmcgbiBpZiBuIGlzIGxlc3MgdGhhbiBvciBlcXVhbCB0byAyDQogICAgICAgcmV0dXJuIG4NCg0KDQogICBtYXhfbGVuID0gMg0KDQoNCiAgIGRwID0gWzJdICogbiAgIyBpbml0aWFsaXppbmcgZHAgd2l0aCAyDQoNCg0KICAgZm9yIGogaW4gcmFuZ2UobiAtIDIsIC0xLCAtMSk6ICAjIHN0YXJ0aW5nIHRvIGl0ZXJhdGUgb3ZlciB0aGUgZWxlbWVudHMNCiAgICAgICBpID0gaiAtIDEgICMgZmluZGluZyBwcmV2aW91cyBlbGVtZW50IG9mIEFQDQogICAgICAgayA9IGogKyAxICAjIGZpbmRpbmcgbmV4dCBlbGVtZW50IG9mIEFQDQoNCg0KICAgICAgIHdoaWxlIGkgPj0gMCBhbmQgayA8IG46ICAjIGl0ZXJhdGluZyB0byBjaGVjayBpZiBhW2ldLCBhW2pdLCBhW2tdIGZvcm0gYW4gQVANCiAgICAgICAgICAgaWYgYVtpXSArIGFba10gPT0gMiAqIGFbal06ICAjIGluY3JlbWVudCBkcFtqXSBpZiBBUCBpcyBmb3JtZWQNCiAgICAgICAgICAgICAgIGRwW2pdID0gbWF4KGRwW2tdICsgMSwgZHBbal0pDQogICAgICAgICAgICAgICBtYXhfbGVuID0gbWF4KG1heF9sZW4sIGRwW2pdKQ0KICAgICAgICAgICAgICAgaSAtPSAxDQogICAgICAgICAgICAgICBrICs9IDENCiAgICAgICAgICAgZWxpZiBhW2ldICsgYVtrXSA8IDIgKiBhW2pdOiAgIyBpbmNyZW1lbnRpbmcgaw0KICAgICAgICAgICAgICAgayArPSAxDQogICAgICAgICAgIGVsc2U6ICAjIGRlY3JlbWVudGluZyBpDQogICAgICAgICAgICAgICBpIC09IDENCg0KDQogICByZXR1cm4gbWF4X2xlbiAgIyByZXR1cm5pbmcgdGhlIGFuc3dlcg0KDQoNCmlmIF9fbmFtZV9fID09ICJfX21haW5fXyI6DQogICBuID0gaW50KGlucHV0KCkpDQogICB2ZWMgPSBsaXN0KG1hcChpbnQsIGlucHV0KCkuc3BsaXQoKSkpDQogICBwcmludChzb2x2ZSh2ZWMpKQ0K
Problem Statement 3
You are a shopkeeper and bought N pairs of socks of several colours in bulk. The colour of each pair of socks is represented as a non-negative integer. The socks are sold as sets of 3 each. A set of socks consists of 3 socks of the same colour.
You want to find the number of different sets that can be made from the N pairs of socks you bought today.
Note: order of indices of sock pairs in the set does not matter.
Question Constraints:
1 <= N <= 105
0 <= ai <= 10^3
Input Format:
The first line of the input contains a single integer N which denotes the number of pairs of socks that you have.
The second line of the input contains n space-separated integers a1, a2, …, an, where ai represents the colour of the ith pair.
Output Format:
Print a single integer representing the total number of different sets of 3 socks that can be formed from the N pairs of socks.
Solution C++
#include<bits/stdc++.h>
usingnamespacestd;
// function to return nC3 value
// for a given n
intnC3(intn){
if(n <3)
return0;
return (n*(n-1)*(n-2))/6;
}
int main(){
// read inputs
int n;
cin >> n;
vectora(n);
for(int&i:a)
cin >> i;
// map to store frequencies
map<int, int> freq;
for(int i: a)
freq[i]++;
// initialize answer as 0
int ans = 0;
// for all elements in the map, add
// nC3 to the answer
map<int, int>::iterator it;
for(it = freq.begin(); it != freq.end(); it++){
ans += nC3(it->second);
}
// print the answer
cout << ans << endl;
return0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmduYW1lc3BhY2VzdGQ7CgovLyBmdW5jdGlvbiB0byByZXR1cm4gbkMzIHZhbHVlCi8vIGZvciBhIGdpdmVuIG4KaW50bkMzKGludG4pewogIGlmKG4gPDMpCiAgICAgIHJldHVybjA7CiAgcmV0dXJuIChuKihuLTEpKihuLTIpKS82Owp9CmludCBtYWluKCl7CiAgLy8gcmVhZCBpbnB1dHMKICBpbnQgbjsKICBjaW4gPj4gbjsKICB2ZWN0b3JhKG4pOwogIGZvcihpbnQmaTphKQogICAgICBjaW4gPj4gaTsKICAvLyBtYXAgdG8gc3RvcmUgZnJlcXVlbmNpZXMKICBtYXA8aW50LCBpbnQ+IGZyZXE7CiAgZm9yKGludCBpOiBhKQogICAgICBmcmVxW2ldKys7CiAgLy8gaW5pdGlhbGl6ZSBhbnN3ZXIgYXMgMAogIGludCBhbnMgPSAwOwogIC8vIGZvciBhbGwgZWxlbWVudHMgaW4gdGhlIG1hcCwgYWRkCiAgLy8gbkMzIHRvIHRoZSBhbnN3ZXIKICBtYXA8aW50LCBpbnQ+OjppdGVyYXRvciBpdDsKICBmb3IoaXQgPSBmcmVxLmJlZ2luKCk7IGl0ICE9IGZyZXEuZW5kKCk7IGl0KyspewogICAgICBhbnMgKz0gbkMzKGl0LT5zZWNvbmQpOwogIH0KCiAgLy8gcHJpbnQgdGhlIGFuc3dlcgogIGNvdXQgPDwgYW5zIDw8IGVuZGw7CiAgcmV0dXJuMDsKfQo=
Solution Python
def nC3(n):
# Function to return nC3 value for a given n
if n < 3:
return 0
return (n * (n - 1) * (n - 2)) // 6 # Combination formula for choosing 3 items from n
def main():
# Read the number of socks
n = int(input())
# Read the colors of the socks
socks = list(map(int, input().split()))
# Dictionary to store frequencies of each color
freq = {}
# Count each sock individually
for sock in socks:
if sock in freq:
freq[sock] += 1
else:
freq[sock] = 1
# Initialize answer as 0
ans = 0
# For all elements in the dictionary, add nC3 to the answer
for count in freq.values():
ans += nC3(count) # Add sets of 3 socks that can be formed from the count
# Print the answer
print(ans)
if __name__ == "__main__":
main()
ZGVmIG5DMyhuKToNCiAgICAjIEZ1bmN0aW9uIHRvIHJldHVybiBuQzMgdmFsdWUgZm9yIGEgZ2l2ZW4gbg0KICAgIGlmIG4gPCAzOg0KICAgICAgICByZXR1cm4gMA0KICAgIHJldHVybiAobiAqIChuIC0gMSkgKiAobiAtIDIpKSAvLyA2ICAjIENvbWJpbmF0aW9uIGZvcm11bGEgZm9yIGNob29zaW5nIDMgaXRlbXMgZnJvbSBuDQoNCmRlZiBtYWluKCk6DQogICAgIyBSZWFkIHRoZSBudW1iZXIgb2Ygc29ja3MNCiAgICBuID0gaW50KGlucHV0KCkpDQoNCiAgICAjIFJlYWQgdGhlIGNvbG9ycyBvZiB0aGUgc29ja3MNCiAgICBzb2NrcyA9IGxpc3QobWFwKGludCwgaW5wdXQoKS5zcGxpdCgpKSkNCg0KICAgICMgRGljdGlvbmFyeSB0byBzdG9yZSBmcmVxdWVuY2llcyBvZiBlYWNoIGNvbG9yDQogICAgZnJlcSA9IHt9DQoNCiAgICAjIENvdW50IGVhY2ggc29jayBpbmRpdmlkdWFsbHkNCiAgICBmb3Igc29jayBpbiBzb2NrczoNCiAgICAgICAgaWYgc29jayBpbiBmcmVxOg0KICAgICAgICAgICAgZnJlcVtzb2NrXSArPSAxDQogICAgICAgIGVsc2U6DQogICAgICAgICAgICBmcmVxW3NvY2tdID0gMQ0KDQogICAgIyBJbml0aWFsaXplIGFuc3dlciBhcyAwDQogICAgYW5zID0gMA0KDQogICAgIyBGb3IgYWxsIGVsZW1lbnRzIGluIHRoZSBkaWN0aW9uYXJ5LCBhZGQgbkMzIHRvIHRoZSBhbnN3ZXINCiAgICBmb3IgY291bnQgaW4gZnJlcS52YWx1ZXMoKToNCiAgICAgICAgYW5zICs9IG5DMyhjb3VudCkgICMgQWRkIHNldHMgb2YgMyBzb2NrcyB0aGF0IGNhbiBiZSBmb3JtZWQgZnJvbSB0aGUgY291bnQNCg0KICAgICMgUHJpbnQgdGhlIGFuc3dlcg0KICAgIHByaW50KGFucykNCg0KaWYgX19uYW1lX18gPT0gIl9fbWFpbl9fIjoNCiAgICBtYWluKCkNCg==
Solution Java
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class SockSets {
// Function to return nC3 value for a given n
public static int nC3(int n) {
if (n < 3)
return 0;
return (n * (n - 1) * (n - 2)) / 6; // Combination formula for choosing 3 items from n
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read number of socks
int n = scanner.nextInt();
int[] socks = new int[n];
// Read the colors of the socks
for (int i = 0; i < n; i++) {
socks[i] = scanner.nextInt();
}
// Map to store frequencies of each color
Map<Integer, Integer> freq = new HashMap<>();
for (int sock : socks) {
freq.put(sock, freq.getOrDefault(sock, 0) + 1); // Count each sock individually
}
// Initialize answer as 0
int ans = 0;
// For all elements in the map, add nC3 to the answer
for (int count : freq.values()) {
ans += nC3(count); // Add sets of 3 socks that can be formed from the count
}
// Print the answer
System.out.println(ans);
}
}
aW1wb3J0IGphdmEudXRpbC5IYXNoTWFwOwppbXBvcnQgamF2YS51dGlsLk1hcDsKaW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKcHVibGljIGNsYXNzIFNvY2tTZXRzIHsKICAgIAogICAgLy8gRnVuY3Rpb24gdG8gcmV0dXJuIG5DMyB2YWx1ZSBmb3IgYSBnaXZlbiBuCiAgICBwdWJsaWMgc3RhdGljIGludCBuQzMoaW50IG4pIHsKICAgICAgICBpZiAobiA8IDMpCiAgICAgICAgICAgIHJldHVybiAwOwogICAgICAgIHJldHVybiAobiAqIChuIC0gMSkgKiAobiAtIDIpKSAvIDY7IC8vIENvbWJpbmF0aW9uIGZvcm11bGEgZm9yIGNob29zaW5nIDMgaXRlbXMgZnJvbSBuCiAgICB9CgogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIFNjYW5uZXIgc2Nhbm5lciA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CgogICAgICAgIC8vIFJlYWQgbnVtYmVyIG9mIHNvY2tzCiAgICAgICAgaW50IG4gPSBzY2FubmVyLm5leHRJbnQoKTsKICAgICAgICBpbnRbXSBzb2NrcyA9IG5ldyBpbnRbbl07CgogICAgICAgIC8vIFJlYWQgdGhlIGNvbG9ycyBvZiB0aGUgc29ja3MKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgICAgICBzb2Nrc1tpXSA9IHNjYW5uZXIubmV4dEludCgpOwogICAgICAgIH0KCiAgICAgICAgLy8gTWFwIHRvIHN0b3JlIGZyZXF1ZW5jaWVzIG9mIGVhY2ggY29sb3IKICAgICAgICBNYXA8SW50ZWdlciwgSW50ZWdlcj4gZnJlcSA9IG5ldyBIYXNoTWFwPD4oKTsKICAgICAgICBmb3IgKGludCBzb2NrIDogc29ja3MpIHsKICAgICAgICAgICAgZnJlcS5wdXQoc29jaywgZnJlcS5nZXRPckRlZmF1bHQoc29jaywgMCkgKyAxKTsgLy8gQ291bnQgZWFjaCBzb2NrIGluZGl2aWR1YWxseQogICAgICAgIH0KCiAgICAgICAgLy8gSW5pdGlhbGl6ZSBhbnN3ZXIgYXMgMAogICAgICAgIGludCBhbnMgPSAwOwoKICAgICAgICAvLyBGb3IgYWxsIGVsZW1lbnRzIGluIHRoZSBtYXAsIGFkZCBuQzMgdG8gdGhlIGFuc3dlcgogICAgICAgIGZvciAoaW50IGNvdW50IDogZnJlcS52YWx1ZXMoKSkgewogICAgICAgICAgICBhbnMgKz0gbkMzKGNvdW50KTsgIC8vIEFkZCBzZXRzIG9mIDMgc29ja3MgdGhhdCBjYW4gYmUgZm9ybWVkIGZyb20gdGhlIGNvdW50CiAgICAgICAgfQoKICAgICAgICAvLyBQcmludCB0aGUgYW5zd2VyCiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKGFucyk7CiAgICB9Cn0K
Problem Statement 4
Alex and Carrie are playing a binary game. In this game, Alex gives Carrie a number, and Carrie's task is to start from 0 and incrementally go up to the given number N. For each number in this range, Carrie must count the number of 1s in its binary representation.
Question Constraints:
1 <= N<= 5*10^6
Input Format:
The input consists of a single character representing the number N.
Output Format:
Print a vector where each element is the count of 1s in the binary representation of numbers from 0 up to N.
Solution C++
C++ code
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read the input value n
int n = sc.nextInt();
int ans = 0; // Variable to store the answer
// Loop through n elements
for (int i = 0; i < n; i++) {
int k = sc.nextInt(); // Read each input number
ans ^= k; // XOR the current answer with the input
}
// Print the result
System.out.println(ans);
}
}
QysrIGNvZGUKaW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKcHVibGljIGNsYXNzIE1haW4gewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIFNjYW5uZXIgc2MgPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwoKICAgICAgICAvLyBSZWFkIHRoZSBpbnB1dCB2YWx1ZSBuCiAgICAgICAgaW50IG4gPSBzYy5uZXh0SW50KCk7CgogICAgICAgIGludCBhbnMgPSAwOyAvLyBWYXJpYWJsZSB0byBzdG9yZSB0aGUgYW5zd2VyCgogICAgICAgIC8vIExvb3AgdGhyb3VnaCBuIGVsZW1lbnRzCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgaW50IGsgPSBzYy5uZXh0SW50KCk7IC8vIFJlYWQgZWFjaCBpbnB1dCBudW1iZXIKICAgICAgICAgICAgYW5zIF49IGs7IC8vIFhPUiB0aGUgY3VycmVudCBhbnN3ZXIgd2l0aCB0aGUgaW5wdXQKICAgICAgICB9CgogICAgICAgIC8vIFByaW50IHRoZSByZXN1bHQKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oYW5zKTsKICAgIH0KfQo=
Solution Python
# Read the input value n
n = int(input())
ans = 0 # Variable to store the answer
# Loop through n elements
for _ in range(n):
k = int(input()) # Read each input number
ans ^= k # XOR the current answer with the input
# Print the result
print(ans)
IyBSZWFkIHRoZSBpbnB1dCB2YWx1ZSBuDQpuID0gaW50KGlucHV0KCkpDQoNCmFucyA9IDAgICMgVmFyaWFibGUgdG8gc3RvcmUgdGhlIGFuc3dlcg0KDQojIExvb3AgdGhyb3VnaCBuIGVsZW1lbnRzDQpmb3IgXyBpbiByYW5nZShuKToNCiAgICBrID0gaW50KGlucHV0KCkpICAjIFJlYWQgZWFjaCBpbnB1dCBudW1iZXINCiAgICBhbnMgXj0gayAgIyBYT1IgdGhlIGN1cnJlbnQgYW5zd2VyIHdpdGggdGhlIGlucHV0DQoNCiMgUHJpbnQgdGhlIHJlc3VsdA0KcHJpbnQoYW5zKQ0K
Solution Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read the input value n
int n = sc.nextInt();
int ans = 0; // Variable to store the answer
// Loop through n elements
for (int i = 0; i < n; i++) {
int k = sc.nextInt(); // Read each input number
ans ^= k; // XOR the current answer with the input
}
// Print the result
System.out.println(ans);
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKcHVibGljIGNsYXNzIE1haW4gewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIFNjYW5uZXIgc2MgPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwoKICAgICAgICAvLyBSZWFkIHRoZSBpbnB1dCB2YWx1ZSBuCiAgICAgICAgaW50IG4gPSBzYy5uZXh0SW50KCk7CgogICAgICAgIGludCBhbnMgPSAwOyAvLyBWYXJpYWJsZSB0byBzdG9yZSB0aGUgYW5zd2VyCgogICAgICAgIC8vIExvb3AgdGhyb3VnaCBuIGVsZW1lbnRzCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgaW50IGsgPSBzYy5uZXh0SW50KCk7IC8vIFJlYWQgZWFjaCBpbnB1dCBudW1iZXIKICAgICAgICAgICAgYW5zIF49IGs7IC8vIFhPUiB0aGUgY3VycmVudCBhbnN3ZXIgd2l0aCB0aGUgaW5wdXQKICAgICAgICB9CgogICAgICAgIC8vIFByaW50IHRoZSByZXN1bHQKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oYW5zKTsKICAgIH0KfQo=
Problem Statement 5
Alex and Carrie are playing a binary game. In this game, Alex gives Carrie a number, and Carrie's task is to start from 0 and incrementally go up to the given number N.
For each number in this range, Carrie must count the number of 1s in its binary representation.
Question Constraints:
1 <= N<= 5*10^6
Input Format:
The input consists of a single character representing the number N.
Output Format:
Print a vector where each element is the count of 1s in the binary representation of numbers from 0 up to N.
Solution C++
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read the input value n
int n = sc.nextInt();
int ans = 0; // Variable to store the answer
// Loop through n elements
for (int i = 0; i < n; i++) {
int k = sc.nextInt(); // Read each input number
ans ^= k; // XOR the current answer with the input
}
// Print the result
System.out.println(ans);
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKcHVibGljIGNsYXNzIE1haW4gewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIFNjYW5uZXIgc2MgPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwoKICAgICAgICAvLyBSZWFkIHRoZSBpbnB1dCB2YWx1ZSBuCiAgICAgICAgaW50IG4gPSBzYy5uZXh0SW50KCk7CgogICAgICAgIGludCBhbnMgPSAwOyAvLyBWYXJpYWJsZSB0byBzdG9yZSB0aGUgYW5zd2VyCgogICAgICAgIC8vIExvb3AgdGhyb3VnaCBuIGVsZW1lbnRzCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgaW50IGsgPSBzYy5uZXh0SW50KCk7IC8vIFJlYWQgZWFjaCBpbnB1dCBudW1iZXIKICAgICAgICAgICAgYW5zIF49IGs7IC8vIFhPUiB0aGUgY3VycmVudCBhbnN3ZXIgd2l0aCB0aGUgaW5wdXQKICAgICAgICB9CgogICAgICAgIC8vIFByaW50IHRoZSByZXN1bHQKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oYW5zKTsKICAgIH0KfQo=
Solution Python
# Read the input value n
n = int(input())
ans = 0 # Variable to store the answer
# Loop through n elements
for _ in range(n):
k = int(input()) # Read each input number
ans ^= k # XOR the current answer with the input
# Print the result
print(ans)
IyBSZWFkIHRoZSBpbnB1dCB2YWx1ZSBuDQpuID0gaW50KGlucHV0KCkpDQoNCmFucyA9IDAgICMgVmFyaWFibGUgdG8gc3RvcmUgdGhlIGFuc3dlcg0KDQojIExvb3AgdGhyb3VnaCBuIGVsZW1lbnRzDQpmb3IgXyBpbiByYW5nZShuKToNCiAgICBrID0gaW50KGlucHV0KCkpICAjIFJlYWQgZWFjaCBpbnB1dCBudW1iZXINCiAgICBhbnMgXj0gayAgIyBYT1IgdGhlIGN1cnJlbnQgYW5zd2VyIHdpdGggdGhlIGlucHV0DQoNCiMgUHJpbnQgdGhlIHJlc3VsdA0KcHJpbnQoYW5zKQ0K
Solution Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read the input value n
int n = sc.nextInt();
int ans = 0; // Variable to store the answer
// Loop through n elements
for (int i = 0; i < n; i++) {
int k = sc.nextInt(); // Read each input number
ans ^= k; // XOR the current answer with the input
}
// Print the result
System.out.println(ans);
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKcHVibGljIGNsYXNzIE1haW4gewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIFNjYW5uZXIgc2MgPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwoKICAgICAgICAvLyBSZWFkIHRoZSBpbnB1dCB2YWx1ZSBuCiAgICAgICAgaW50IG4gPSBzYy5uZXh0SW50KCk7CgogICAgICAgIGludCBhbnMgPSAwOyAvLyBWYXJpYWJsZSB0byBzdG9yZSB0aGUgYW5zd2VyCgogICAgICAgIC8vIExvb3AgdGhyb3VnaCBuIGVsZW1lbnRzCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgaW50IGsgPSBzYy5uZXh0SW50KCk7IC8vIFJlYWQgZWFjaCBpbnB1dCBudW1iZXIKICAgICAgICAgICAgYW5zIF49IGs7IC8vIFhPUiB0aGUgY3VycmVudCBhbnN3ZXIgd2l0aCB0aGUgaW5wdXQKICAgICAgICB9CgogICAgICAgIC8vIFByaW50IHRoZSByZXN1bHQKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oYW5zKTsKICAgIH0KfQo=
Preparation Tips for Accenture Coding Round
- Focus on Core Data Structures and Algorithms: Strong understanding of arrays, strings, sorting, searching, and dynamic programming is crucial. Practice coding problems on platforms like LeetCode, HackerRank, and CodeSignal.
- Practice Time-Management: Accenture coding rounds are time-bound. Practice solving problems within a limited timeframe to simulate real exam conditions.
- Work on Problem-Solving Skills: Before jumping into coding, take time to break down the problem logically. Write pseudocode, and only then move to actual coding. This approach helps in managing complex problems.
- Review Previous Year’s Coding Questions: Solving previous year's coding questions can help you identify common problem types and the level of difficulty you can expect during the test.
- Improve Coding Speed: Focus on improving your coding speed without compromising on accuracy. Regular practice of coding challenges will help you build speed over time.
Conclusion
The Accenture coding round is designed to test your ability to solve complex problems efficiently using coding skills and logical reasoning. By focusing on data structures, algorithms, pseudo code, and problem-solving techniques, you can effectively prepare for this crucial part of the recruitment process.
Regular practice of coding questions, understanding time complexity, and working on pseudo code will greatly enhance your chances of cracking the Accenture coding round.
Frequently Asked Questions (FAQs)
1. What topics should I focus on for Accenture’s coding round?
Focus on core data structures (arrays, strings, linked lists), algorithms (sorting, searching), and problem-solving techniques such as recursion and dynamic programming.
2. How can I improve my speed in solving Accenture coding questions?
Practice coding regularly within a time limit, and work on improving your problem-solving approach by analysing the problem before coding.
3. Is pseudo code important in Accenture’s coding round?
Yes, pseudo code is important as it tests your ability to break down problems logically and represent solutions before coding them.
4. How many coding questions are there in the Accenture coding round?
The coding round typically consists of 2-3 questions, with a mix of algorithmic, data structure, and mathematical problems.
5. Where can I find the previous year's Accenture coding questions?
Previous year coding questions can be found on coding practice platforms, forums, and preparation websites available online.
Disclaimer: While we strive for accuracy, we do not guarantee its completeness or reliability. Readers are encouraged to verify all facts and statistics from the official company website or check independently before making decisions.
Suggested reads:
- Detailed Exam Syllabus of Accenture: A Guide for Freshers 2025
- Eligibility Criteria for Accenture: Freshers' Guide for 2025
- Accenture Technical Assessment 2025: A Detailed Guide for Freshers
- Latest Accenture Communication Assessment: A Guide for Freshers 2025
- Accenture Previous Year Papers: Placement Guide for Freshers 2025
Instinctively, I fall for nature, music, humor, reading, writing, listening, traveling, observing, learning, unlearning, friendship, exercise, etc., all these from the cradle to the grave- that's ME! It's my irrefutable belief in the uniqueness of all. I'll vehemently defend your right to be your best while I expect the same from you!
Login to continue reading
And access exclusive content, personalized recommendations, and career-boosting opportunities.
Subscribe
to our newsletter
Blogs you need to hog!
How To Write Finance Cover Letter For Morgan Stanley (+Free Sample!)
55+ Data Structure Interview Questions For 2025 (Detailed Answers)
How To Negotiate Salary With HR: Tips And Insider Advice
Comments
Add comment