Accenture Most Asked Coding Questions with Java Solutions
Follow Our WhatsApp Group To Get More Update’s And Preparation Material’s.
In this blog, we will explore the most frequently asked coding questions in Accenture’s placement exams and technical interviews. Each question is accompanied by a detailed explanation and a Java solution to help you prepare efficiently.
If you’re preparing for an Accenture coding test, these problems will give you insight into the types of questions you may encounter. Mastering them will enhance your coding skills and build confidence for technical interviews.
Accenture Most Asked Coding Questions with Java Solutions
In this blog, we will explore the most frequently asked coding questions in Accenture’s placement exams and technical interviews. Each question is accompanied by a detailed explanation and a Java solution to help you prepare efficiently.
If you’re preparing for an Accenture coding test, these problems will give you insight into the types of questions you may encounter. Mastering them will enhance your coding skills and build confidence for technical interviews.
Accenture Placement Materials Link: Click
Table of Contents
Toggle1) Sum of Binary Digits
Problem Statement:
You are given a number N
. Convert the number to its binary form and return the sum of its binary digits (i.e., the number of 1
s in the binary representation).
Example:
Input: 15
Output: Binary of 15 is 1111, so the sum is 4.
Java Solution:
public class BinarySum {
public static int binarySum(int n) {
return Integer.toBinaryString(n).replace("0", "").length();
}
public static void main(String[] args) {
int n = 15;
System.out.println("Sum of binary digits: " + binarySum(n));
}}
2) Find the Second Smallest Element in an Array
Problem Statement:
Given an array, find the second smallest element in the array.
Example:
Input: [3, 1, 4, 1, 5]
Output: 3
Java Solution:
import java.util.*;
public class SecondSmallest {
public static Integer secondSmallest(int[] arr) {
TreeSet<Integer> uniqueSorted = new TreeSet<>();
for (int num : arr) uniqueSorted.add(num);
return uniqueSorted.size() > 1 ? (Integer) uniqueSorted.toArray()[1] : null;
}
public static void main(String[] args) {
int[] arr = {3, 1, 4, 1, 5};
System.out.println("Second smallest element: " + secondSmallest(arr));
}
}
3) Shorten Word with Middle Character Count
Problem Statement:
Given a word, return a string that contains the first letter, the count of the middle characters, and the last letter.
Example:
Input: examination
Output: e9n
Java Solution:
public class ShortenWord {
public static String shortenWord(String word) {
return word.charAt(0) + String.valueOf(word.length() - 2) + word.charAt(word.length() - 1);
}
public static void main(String[] args) {
String word = "examination";
System.out.println("Shortened word: " + shortenWord(word));
}
}
4) Prime Numbers Between 1 and N
Problem Statement:
Print all prime numbers between 1
and N
.
Example:
Input: N = 50
Output: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
Java Solution:
import java.util.ArrayList;
import java.util.List;
public class PrimeNumbers {
public static List<Integer> primesUptoN(int n) {
List<Integer> primes = new ArrayList<>();
for (int i = 2; i <= n; i++) {
if (isPrime(i)) primes.add(i);
}
return primes;
}
private static boolean isPrime(int num) {
if (num < 2) return false;
for (int i = 2; i <= Math.sqrt(num); i++) {
if (num % i == 0) return false;
}
return true;
}
public static void main(String[] args) {
int n = 50;
System.out.println("Prime numbers up to " + n + ": " + primesUptoN(n));
}
}
5) Print Floyd’s Triangle
Problem Statement:
Print Floyd’s triangle with N
rows.
Example:
Input: N = 5
Java Solution:
public class FloydTriangle {
public static void floydTriangle(int n) {
int num = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(num + " ");
num++;
}
System.out.println();
}
}
public static void main(String[] args) {
int rows = 5;
floydTriangle(rows);
}
}
6) Check Leap Year
Problem Statement:
Write a program to check if a given year is a leap year or not.
Example:
Input: 2024
Output: true (2024 is a leap year)
Java Solution:
public class LeapYear {
public static boolean isLeapYear(int year) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
public static void main(String[] args) {
int year = 2024;
System.out.println(year + " is a leap year? " + isLeapYear(year));
}
}
7) Sum of Even and Odd Elements in an Array
Problem Statement:
Given an array, calculate the sum of even and odd elements separately.
Example:
Input: [1, 2, 3, 4, 5, 6]
Output: Even Sum: 12, Odd Sum: 9
Java Solution:
public class EvenOddSum {
public static void sumEvenOdd(int[] arr) {
int evenSum = 0, oddSum = 0;
for (int num : arr) {
if (num % 2 == 0) evenSum += num;
else oddSum += num;
}
System.out.println("Even sum: " + evenSum);
System.out.println("Odd sum: " + oddSum);
}
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5, 6};
sumEvenOdd(arr);
}
}
8) Vowel Permutation
Problem Statement:
Given a string, print all possible permutations of the vowels present in the string.
Example:
Input: “accenture”
Output: Permutations of vowels: [ae, ea]
Java Solution:
import java.util.*;
public class VowelPermutations {
public static List<String> vowelPermutations(String str) {
List<Character> vowels = new ArrayList<>();
for (char c : str.toCharArray()) {
if ("aeiou".indexOf(c) != -1) vowels.add(c);
}
List<String> permutations = new ArrayList<>();
permute("", vowels, permutations);
return permutations;
}
private static void permute(String prefix, List<Character> remaining, List<String> result) {
if (remaining.isEmpty()) result.add(prefix);
else {
for (int i = 0; i < remaining.size(); i++) {
List<Character> next = new ArrayList<>(remaining);
char ch = next.remove(i);
permute(prefix + ch, next, result);
}
}
}
public static void main(String[] args) {
String word = "accenture";
System.out.println("Vowel permutations: " + vowelPermutations(word));
}
}
9) Reverse the Array and Print Odd and Even Positions
Problem Statement:
Reverse the given array and then print the elements at even and odd positions in a string format.
Example:
Input: [10, 20, 30, 40, 50]
Output: Even positions: [20, 40], Odd positions: [50, 30, 10]
Java Solution:
import java.util.*;
public class ReverseArray {
public static void reverseAndPositions(int[] arr) {
List<Integer> evenPos = new ArrayList<>();
List<Integer> oddPos = new ArrayList<>();
for (int i = arr.length - 1; i >= 0; i--) {
if ((arr.length - i) % 2 == 0) evenPos.add(arr[i]);
else oddPos.add(arr[i]);
}
System.out.println("Even positions: " + evenPos);
System.out.println("Odd positions: " + oddPos);
}
public static void main(String[] args) {
int[] arr = {10, 20, 30, 40, 50};
reverseAndPositions(arr);
}
}
10) Print the Winning Team of a Football Match
Problem Statement:
Given the number of teams and their goals, find the team with the maximum number of goals.
Example:
Input: Teams = [“Team A”, “Team B”, “Team C”], Goals = [5, 2, 3]
Output: Winning team: Team A
Java Solution:
public class WinningTeam {
public static String winningTeam(String[] teams, int[] goals) {
int maxGoals = Integer.MIN_VALUE;
int winnerIndex = 0;
for (int i = 0; i < goals.length; i++) {
if (goals[i] > maxGoals) {
maxGoals = goals[i];
winnerIndex = i;
}
}
return teams[winnerIndex];
}
public static void main(String[] args) {
String[] teams = {"Team A", "Team B", "Team C"};
int[] goals = {5, 2, 3};
System.out.println("Winning team: " + winningTeam(teams, goals));
}
}
11) Maximum Chocolates
Problem Statement:
You are given an array of chocolate prices. If the price is divisible by 5, it’s free. Find the maximum number of chocolates a person can buy.
Example:
Input: [10, 15, 20, 25, 7, 9]
Output: 4
Java Solution:
public class MaxChocolates {
public static int maxChocolates(int[] prices) {
int freeChocolates = 0;
for (int price : prices) {
if (price % 5 == 0) freeChocolates++;
}
return freeChocolates;
}
public static void main(String[] args) {
int[] chocolatePrices = {10, 15, 20, 25, 7, 9};
System.out.println("Maximum chocolates you can buy: " + maxChocolates(chocolatePrices));
}
}
JOBS: 1 Apply for DELOITTE.
Comment for more content like this (Company Oriented)
Key Words:
-
- Accenture coding questions
-
- Accenture placement preparation
-
- Accenture coding test solutions
-
- Frequently asked coding questions
-
- Accenture technical interview preparation
-
- Java solutions for Accenture questions
-
- Accenture placement materials
-
- Sum of binary digits problem
-
- Find second smallest element in Java
-
- Floyd’s triangle Java solution
-
- Prime number coding question
-
- Check leap year program
-
- Reverse array and positions in Java
-
- Accenture coding exam questions
-
- Sum of even and odd elements array
-
- Vowel permutations in string
-
- Winning team problem Accenture
-
- Maximum chocolates coding question
-
- Accenture coding questions with detailed Java solutions
-
- How to prepare for Accenture placement tests in Java
-
- Most asked coding questions in Accenture 2024 exams
-
- Java programs for placement preparation
-
- Coding questions to crack Accenture interviews
-
- Title: Accenture Coding Questions with Java Solutions: Top Interview Prep Questions 2024
-
- Description: Discover frequently asked coding questions in Accenture’s exams and technical interviews. Get detailed Java solutions to boost your preparation.
Çatalca su kaçak tespiti Dairemizde yaşanan su kaçağını bulmak için gelen ekip çok bilgiliydi. Her aşamayı detaylı açıkladılar. Nazan E.