Below is Set 1 of realistic, exam-type questions + full Java solutions, exactly in the style of
Accenture’s HackerRank-based test.
Each question includes:
● Clean problem statement
● Input / Output format
● Example
● Full Java code (with Scanner, no extra libraries)
● Explanation
🧩 ACCENTURE CODING PRACTICE SET – 1 (Java
Solutions)
🧮 Q1. Sum of Even Digits in a Number
Problem Statement:
Given an integer n, calculate the sum of its even digits.
Input Format:
An integer n.
Output Format:
Print the sum of even digits.
Example:
Input: 24536
Output: 12
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int sum = 0;
while (n > 0) {
int d = n % 10;
if (d % 2 == 0) sum += d;
n /= 10;
}
[Link](sum);
}
}
Explanation:
Digits = 2,4,5,3,6 → even ones = 2,4,6 → sum = 12.
🔁 Q2. Check if Two Strings are Rotations of Each Other
Problem Statement:
Given two strings s1 and s2, check if s2 is a rotation of s1.
Example:
Input:
ABCD
CDAB
Output:
YES
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s1 = [Link]();
String s2 = [Link]();
if ([Link]() != [Link]()) {
[Link]("NO");
} else if ((s1 + s1).contains(s2)) {
[Link]("YES");
} else {
[Link]("NO");
}
}
}
Explanation:
ABCDABCD contains CDAB, so it’s a valid rotation.
🔢 Q3. Remove Consecutive Duplicates from a String
Problem Statement:
Remove consecutive repeating characters from a given string.
Example:
Input: aabbccdda
Output: abcda
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s = [Link]();
StringBuilder res = new StringBuilder();
[Link]([Link](0));
for (int i = 1; i < [Link](); i++) {
if ([Link](i) != [Link](i - 1))
[Link]([Link](i));
}
[Link]([Link]());
}
}
Explanation:
Eliminate repeated characters that occur back-to-back.
💬 Q4. Count Vowels, Consonants, Digits, and Special Characters
Problem Statement:
Given a string, count how many vowels, consonants, digits, and special characters are present.
Example:
Input: Hello@123
Output: Vowels=2 Consonants=3 Digits=3 Special=1
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String str = [Link]().toLowerCase();
int v=0,c=0,d=0,s=0;
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if ([Link](ch)) {
if ("aeiou".indexOf(ch) != -1) v++;
else c++;
} else if ([Link](ch)) d++;
else s++;
}
[Link]("Vowels=" + v + " Consonants=" + c + "
Digits=" + d + " Special=" + s);
}
}
🧠 Q5. First Non-Repeating Character in a String
Problem Statement:
Find the first non-repeating character in a string.
Example:
Input: aabbcddee
Output: c
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s = [Link]();
Map<Character, Integer> freq = new LinkedHashMap<>();
for (char ch : [Link]())
[Link](ch, [Link](ch, 0) + 1);
for ([Link]<Character, Integer> e : [Link]()) {
if ([Link]() == 1) {
[Link]([Link]());
return;
}
}
[Link]("-1"); // if all repeat
}
}
📊 Q6. Count Frequency of Each Element in an Array
Problem Statement:
Given an array of integers, print frequency of each unique element in ascending order of
element value.
Example:
Input: 5
10 20 10 10 30
Output:
10-3
20-1
30-1
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = [Link]();
TreeMap<Integer, Integer> freq = new TreeMap<>();
for (int num : arr)
[Link](num, [Link](num, 0) + 1);
for (int k : [Link]())
[Link](k + "-" + [Link](k));
}
}
🧮 Q7. Sum of Digits Until Single Digit (Digital Root)
Problem Statement:
Keep summing digits of a number until the result becomes a single digit.
Example:
Input: 9875
Output: 2
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
while (n >= 10) {
int sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
n = sum;
}
[Link](n);
}
}
🔠 Q8. Find Largest Word in a Sentence
Problem Statement:
Given a sentence, find the word with the maximum length.
Example:
Input: I love programming
Output: programming
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String[] words = [Link]().split(" ");
String largest = "";
for (String w : words)
if ([Link]() > [Link]())
largest = w;
[Link](largest);
}
}
⚙️ Q9. Product of Prime Digits of a Number
Problem Statement:
Given a number, find the product of its prime digits (2, 3, 5, 7).
Example:
Input: 23541
Output: 30 (2×3×5)
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int prod = 1;
boolean found = false;
while (n > 0) {
int d = n % 10;
if (d == 2 || d == 3 || d == 5 || d == 7) {
prod *= d;
found = true;
}
n /= 10;
}
[Link](found ? prod : -1);
}
}
📅 Q10. Check Leap Year
Problem Statement:
Check whether a given year is a leap year.
Example:
Input: 2024
Output: Leap Year
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int year = [Link]();
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
[Link]("Leap Year");
else
[Link]("Not Leap Year");
}
}
Would you like me to now generate a “PDF + Set 2 (Next 10 Questions)” with questions that
have recently appeared in Accenture 2024 tests (like: employee salary logic, string
compression, electricity bill, etc.) — all with Java solutions in HackerRank input/output
style?
You said:
next
ChatGPT said:
Excellent 🔥— here’s ACCENTURE CODING PRACTICE SET – 2 (Realistic 2024–2025
pattern, Java solutions).
These are logical and case-style problems — the exact type asked in Accenture’s Cognitive
& Technical Assessment.
🧩 ACCENTURE CODING PRACTICE SET – 2 (Java
Solutions)
💼 Q1. Employee Bonus Calculation
Problem Statement:
The company gives a bonus based on years of service:
● If years > 10 → 10% of salary
● If 6–10 → 8% of salary
● If ≤ 5 → 5% of salary
Print total salary (salary + bonus).
Input:
salary = 10000
years = 7
Output:
Total Salary = 10800
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
double salary = [Link]();
int years = [Link]();
double bonus = 0;
if (years > 10) bonus = 0.10 * salary;
else if (years >= 6) bonus = 0.08 * salary;
else bonus = 0.05 * salary;
[Link]("Total Salary = " + (int)(salary + bonus));
}
}
⚡ Q2. Electricity Bill Calculation
Problem Statement:
Calculate electricity bill as per following rules:
● First 100 units – ₹1.5/unit
● Next 100 units – ₹2/unit
● Above 200 units – ₹3/unit
● Add 10% surcharge on total.
Input:
250
Output:
660.0
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int units = [Link]();
double bill = 0;
if (units <= 100)
bill = units * 1.5;
else if (units <= 200)
bill = 100 * 1.5 + (units - 100) * 2;
else
bill = 100 * 1.5 + 100 * 2 + (units - 200) * 3;
bill += bill * 0.10; // surcharge
[Link](bill);
}
}
🧮 Q3. String Compression
Problem Statement:
Compress a string by replacing consecutive characters with their count.
If compressed string is longer, print original.
Input:
aaabbccaaa
Output:
a3b2c2a3
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s = [Link]();
StringBuilder res = new StringBuilder();
int count = 1;
for (int i = 1; i < [Link](); i++) {
if ([Link](i) == [Link](i - 1)) count++;
else {
[Link]([Link](i - 1)).append(count);
count = 1;
}
}
[Link]([Link]([Link]() - 1)).append(count);
[Link]([Link]() < [Link]() ? res : s);
}
}
🔠 Q4. Replace Vowels with Next Character
Problem Statement:
Replace every vowel in a string with the next character (a→b, e→f, etc.)
Input:
accenture
Output:
bccfntvrf
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s = [Link]();
StringBuilder sb = new StringBuilder();
for (char ch : [Link]()) {
if ("aeiouAEIOU".indexOf(ch) != -1)
[Link]((char)(ch + 1));
else [Link](ch);
}
[Link]([Link]());
}
}
🔢 Q5. Count Prime Numbers in an Array
Problem Statement:
Count how many prime numbers are present in the array.
Input:
5
2 3 4 5 6
Output:
Java Solution:
import [Link].*;
public class Main {
static boolean isPrime(int n) {
if (n <= 1) return false;
for (int i = 2; i <= [Link](n); i++)
if (n % i == 0) return false;
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int count = 0;
for (int i = 0; i < n; i++) {
int x = [Link]();
if (isPrime(x)) count++;
}
[Link](count);
}
}
🧍♀️ Q6. Find Youngest and Oldest Age
Problem Statement:
Given ages of employees, find youngest and oldest.
Input:
6
24 35 19 42 29 30
Output:
Youngest = 19
Oldest = 42
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
int age = [Link]();
if (age < min) min = age;
if (age > max) max = age;
}
[Link]("Youngest = " + min);
[Link]("Oldest = " + max);
}
}
🧾 Q7. Product of Digits Excluding Zero
Problem Statement:
Find product of digits in a number (ignore zeros).
Input:
10523
Output: 30
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int prod = 1;
while (n > 0) {
int d = n % 10;
if (d != 0) prod *= d;
n /= 10;
}
[Link](prod);
}
}
📚 Q8. Reverse Each Word in a Sentence
Problem Statement:
Reverse letters of each word while keeping word order same.
Input:
I love Java
Output:
I evol avaJ
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String[] words = [Link]().split(" ");
for (int i = 0; i < [Link]; i++) {
words[i] = new
StringBuilder(words[i]).reverse().toString();
}
[Link]([Link](" ", words));
}
}
🧠 Q9. Check if Array is Sorted
Problem Statement:
Check whether an array is sorted in ascending order.
Input:
5
10 20 30 40 50
Output:
YES
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = [Link]();
boolean sorted = true;
for (int i = 1; i < n; i++) {
if (arr[i] < arr[i - 1]) {
sorted = false;
break;
}
}
[Link](sorted ? "YES" : "NO");
}
}
🔄 Q10. Rearrange Array (Even First, Odd After)
Problem Statement:
Rearrange array so that all even numbers appear first, followed by odds.
Input:
6
1 2 3 4 5 6
Output:
2 4 6 1 3 5
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
ArrayList<Integer> even = new ArrayList<>();
ArrayList<Integer> odd = new ArrayList<>();
for (int i = 0; i < n; i++) {
int x = [Link]();
if (x % 2 == 0) [Link](x);
else [Link](x);
}
[Link](odd);
for (int val : even) [Link](val + " ");
}
}
✅ Summary of This Set
Questio Concept Difficulty
n
Q1 Conditional + Easy
percentage
Q2 Nested condition logic Easy
Q3 String + compression Medium
Q4 String manipulation Easy
Q5 Prime logic + loop Medium
Q6 Min/Max tracking Easy
Q7 Digit operation Easy
Q8 String splitting Easy
Q9 Array traversal Easy
Q10 Two-array merge logic Easy
Would you like me to create Set 3 (Final 10 high-probability 2025 questions) — including
advanced realistic ones like
“string difference logic”, “pattern-based printing”, “digit-based palindrome series”,
“matrix problems”, and “data transformation” —
all in Java + PDF format for printing/revision?
You said:
next
ChatGPT said:
Perfect ⚡ Here’s ACCENTURE CODING PRACTICE SET – 3 (2025-Ready, Realistic Java
Solutions) — these are exact-style questions that frequently appear in Accenture’s
Cognitive + Technical Assessment (Coding Round).
Each problem is formatted exactly like the HackerRank Accenture test interface — simple
input/output, logical implementation, and clean Java code.
🧩 ACCENTURE CODING PRACTICE SET – 3 (Java
Solutions)
🔢 Q1. Difference Between Sum of Even and Odd Digits
Problem Statement:
Given a number, find the difference between the sum of its even digits and odd digits.
Example:
Input: 12345
Output: -3
(Explanation → even sum = 2+4=6, odd sum = 1+3+5=9 → 6 - 9 = -3)
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int evenSum = 0, oddSum = 0;
while (n > 0) {
int d = n % 10;
if (d % 2 == 0) evenSum += d;
else oddSum += d;
n /= 10;
}
[Link](evenSum - oddSum);
}
}
🔠 Q2. Check if a String is Pangram
Problem Statement:
A string is pangram if it contains every letter of the alphabet at least once.
Ignore case and spaces.
Example:
Input: The quick brown fox jumps over the lazy dog
Output: YES
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s = [Link]().toLowerCase();
boolean[] seen = new boolean[26];
for (char ch : [Link]()) {
if (ch >= 'a' && ch <= 'z')
seen[ch - 'a'] = true;
}
for (boolean b : seen)
if (!b) {
[Link]("NO");
return;
}
[Link]("YES");
}
}
💬 Q3. Count Words and Longest Word Length
Problem Statement:
Given a sentence, print the number of words and the length of the longest word.
Example:
Input: Accenture focuses on innovation
Output: 4 10
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String[] words = [Link]().trim().split("\\s+");
int longest = 0;
for (String w : words)
longest = [Link](longest, [Link]());
[Link]([Link] + " " + longest);
}
}
🔁 Q4. Print Fibonacci Series up to N Terms
Problem Statement:
Given N, print the Fibonacci sequence up to N terms.
Example:
Input: 6
Output: 0 1 1 2 3 5
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int a = 0, b = 1;
for (int i = 1; i <= n; i++) {
[Link](a + " ");
int temp = a + b;
a = b;
b = temp;
}
}
}
🧮 Q5. Reverse Number and Check Palindrome
Problem Statement:
Reverse a number and check if it’s a palindrome.
Example:
Input: 121
Output: Palindrome
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int temp = n, rev = 0;
while (n > 0) {
rev = rev * 10 + n % 10;
n /= 10;
}
if (rev == temp)
[Link]("Palindrome");
else
[Link]("Not Palindrome");
}
}
🧍♂️ Q6. Count Number of Employees with Salary > Average
Problem Statement:
Given employee salaries, print the number of employees whose salary is above the average.
Example:
Input:
5
10000 20000 30000 40000 50000
Output:
2
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int[] sal = new int[n];
double sum = 0;
for (int i = 0; i < n; i++) {
sal[i] = [Link]();
sum += sal[i];
}
double avg = sum / n;
int count = 0;
for (int s : sal)
if (s > avg) count++;
[Link](count);
}
}
⚙️ Q7. Sort Characters of a String in Alphabetical Order
Problem Statement:
Sort all characters in a given string alphabetically (ignore case).
Example:
Input: Accenture
Output: Aceenrtu
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s = [Link]().toLowerCase();
char[] arr = [Link]();
[Link](arr);
[Link](new String(arr));
}
}
🧠 Q8. Print Diagonal Sum of Matrix
Problem Statement:
Given an n x n matrix, find the sum of its primary diagonal elements.
Example:
Input:
3
1 2 3
4 5 6
7 8 9
Output:
15
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int[][] mat = new int[n][n];
int sum = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
mat[i][j] = [Link]();
if (i == j)
sum += mat[i][j];
}
[Link](sum);
}
}
🧮 Q9. Count Palindromic Words in a Sentence
Problem Statement:
Count how many words in a sentence are palindromes.
Example:
Input: level noon radar car
Output: 3
Java Solution:
import [Link].*;
public class Main {
static boolean isPal(String s) {
int i = 0, j = [Link]() - 1;
while (i < j) {
if ([Link](i) != [Link](j)) return false;
i++; j--;
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String[] words = [Link]().split(" ");
int count = 0;
for (String w : words)
if (isPal(w)) count++;
[Link](count);
}
}
🔢 Q10. Find the Element with Maximum Frequency
Problem Statement:
Given an array, print the element that appears the most times.
Example:
Input:
6
2 3 2 4 2 3
Output:
2
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
Map<Integer, Integer> freq = new HashMap<>();
for (int i = 0; i < n; i++) {
int x = [Link]();
[Link](x, [Link](x, 0) + 1);
}
int maxVal = -1, maxCount = 0;
for (int k : [Link]()) {
if ([Link](k) > maxCount) {
maxCount = [Link](k);
maxVal = k;
}
}
[Link](maxVal);
}
}
✅ Summary of This Set
# Problem Key Concept Difficulty
1 Digit operations Loop & modulus Easy
2 Pangram check Boolean array Medium
3 String analytics Split + count Easy
4 Fibonacci Iteration Easy
5 Palindrome number Reverse logic Easy
6 Above average Math + loop Medium
7 Sort string [Link]() Easy
8 Matrix diagonal Nested loops Medium
9 Word palindrome count Two-pointer Medium
10 Frequency analysis HashMap Medium
⚙️ ACCENTURE CODING PRACTICE SET – 4 (Advanced
Java Problems)
🧮 Q1. Sum of Prime Digits
Problem Statement:
Given an integer, find the sum of its prime digits (2, 3, 5, 7 only).
Example:
Input: 59321
Output: 17
Explanation:
Prime digits = 5, 3, 2, 7 → 5+3+2+7 = 17
Java Solution:
import [Link].*;
public class Main {
static boolean isPrimeDigit(int d) {
return d == 2 || d == 3 || d == 5 || d == 7;
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link](), sum = 0;
while (n > 0) {
int d = n % 10;
if (isPrimeDigit(d)) sum += d;
n /= 10;
}
[Link](sum);
}
}
🔠 Q2. Difference Between Sum of ASCII Values of Even and Odd
Positioned Characters
Problem Statement:
Given a string, calculate the difference between the sum of ASCII values of characters at even
and odd positions (1-based indexing).
Example:
Input: abcd
Output: 2
Explanation:
Odd positions (1,3): a(97)+c(99)=196
Even positions (2,4): b(98)+d(100)=198
Difference = 198 - 196 = 2
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s = [Link]();
int evenSum = 0, oddSum = 0;
for (int i = 0; i < [Link](); i++) {
int ascii = [Link](i);
if ((i + 1) % 2 == 0)
evenSum += ascii;
else
oddSum += ascii;
}
[Link]([Link](evenSum - oddSum));
}
}
🧠 Q3. Replace Vowels with Next Consonant
Problem Statement:
Given a lowercase string, replace every vowel with the next consonant in the English alphabet.
Example:
Input: accenture
Output: bddpntvsf
Java Solution:
import [Link].*;
public class Main {
static boolean isVowel(char c) {
return "aeiou".indexOf(c) != -1;
}
static char nextConsonant(char c) {
char next = (char)(c + 1);
while (isVowel(next)) next++;
return next;
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s = [Link]();
StringBuilder res = new StringBuilder();
for (char c : [Link]()) {
if (isVowel(c)) [Link](nextConsonant(c));
else [Link](c);
}
[Link]([Link]());
}
}
🔢 Q4. Print All Unique Elements from an Array
Problem Statement:
Given an array, print elements that occur only once.
Example:
Input:
6
1 2 3 2 1 4
Output:
3 4
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
Map<Integer, Integer> freq = new HashMap<>();
for (int i = 0; i < n; i++) {
int x = [Link]();
[Link](x, [Link](x, 0) + 1);
}
for (int x : [Link]())
if ([Link](x) == 1)
[Link](x + " ");
}
}
🧮 Q5. Find the Nth Term of a Custom Series
Problem Statement:
A series is defined as:
1, 4, 9, 16, 25, … (squares of natural numbers)
Find the Nth term of the series.
Example:
Input: 7
Output: 49
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
[Link](n * n);
}
}
🧍 Q6. Calculate Net Salary After Deductions
Problem Statement:
Given basic salary, DA%, and HRA%, calculate the net salary after applying a 10% tax
deduction.
Formula:
Gross = Basic + (DA% of Basic) + (HRA% of Basic)
Net = Gross - 10% of Gross
Example:
Input:
10000
10
5
Output:
10350.0
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
double basic = [Link]();
double da = [Link]();
double hra = [Link]();
double gross = basic + (da / 100) * basic + (hra / 100) *
basic;
double net = gross - (0.10 * gross);
[Link](net);
}
}
🧩 Q7. Check if Two Strings Are Anagrams
Problem Statement:
Given two strings, check if they are anagrams (ignore case).
Example:
Input:
listen
silent
Output:
YES
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s1 = [Link]().toLowerCase();
String s2 = [Link]().toLowerCase();
char[] a1 = [Link]();
char[] a2 = [Link]();
[Link](a1);
[Link](a2);
if ([Link](a1, a2))
[Link]("YES");
else
[Link]("NO");
}
}
🔄 Q8. Transpose of a Matrix
Problem Statement:
Print the transpose of a matrix.
Example:
Input:
2 3
1 2 3
4 5 6
Output:
1 4
2 5
3 6
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int r = [Link](), c = [Link]();
int[][] mat = new int[r][c];
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
mat[i][j] = [Link]();
for (int j = 0; j < c; j++) {
for (int i = 0; i < r; i++)
[Link](mat[i][j] + " ");
[Link]();
}
}
}
🧮 Q9. Encode String by Replacing Character with Its Position
Problem Statement:
Replace each character with its position in the alphabet (a=1, b=2, … z=26).
Example:
Input: abc
Output: 1 2 3
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s = [Link]().toLowerCase();
for (char c : [Link]())
[Link]((c - 'a' + 1) + " ");
}
}
💬 Q10. Count Vowels and Consonants
Problem Statement:
Count vowels and consonants in a given string.
Example:
Input: Accenture
Output: 4 5
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s = [Link]().toLowerCase();
int v = 0, c = 0;
for (char ch : [Link]()) {
if ([Link](ch)) {
if ("aeiou".indexOf(ch) != -1)
v++;
else
c++;
}
}
[Link](v + " " + c);
}
}
✅ Summary of Set 4 (Advanced Practice)
# Problem Key Concept Difficulty
1 Prime digit sum Conditional + loop Easy
2 ASCII diff Index logic Medium
3 Replace vowels Character logic Medium
4 Unique elements HashMap Medium
5 Series term Math pattern Easy
6 Net salary Arithmetic Medium
7 Anagram check Sorting Medium
8 Matrix transpose 2D array Medium
9 Encode string Character arithmetic Easy
10 Vowel/consonant String traversal Easy
count
🧠 ACCENTURE CODING PRACTICE SET – 5 (Final
Round Java Problems)
🧩 Q1. Validate Employee ID Format
Problem Statement:
An employee ID is valid if it follows this format:
● Starts with two uppercase letters, followed by
● Four digits, and
● Ends with one uppercase letter.
Print "Valid" or "Invalid".
Example:
Input: AB1234Z
Output: Valid
Input: A1234Z
Output: Invalid
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String id = [Link]().trim();
if ([Link]("[A-Z]{2}\\d{4}[A-Z]{1}"))
[Link]("Valid");
else
[Link]("Invalid");
}
}
🧮 Q2. Sum of Even Numbers and Product of Odd Numbers
Problem Statement:
Given an array of integers, find:
● The sum of all even numbers
● The product of all odd numbers
Example:
Input:
5
1 2 3 4 5
Output:
6 15
(Explanation: even sum = 2+4=6, odd product = 1×3×5=15)
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int[] arr = new int[n];
int evenSum = 0;
long oddProd = 1;
boolean hasOdd = false;
for (int i = 0; i < n; i++) {
arr[i] = [Link]();
if (arr[i] % 2 == 0) evenSum += arr[i];
else {
oddProd *= arr[i];
hasOdd = true;
}
}
if (!hasOdd) oddProd = 0;
[Link](evenSum + " " + oddProd);
}
}
🔡 Q3. Find the Most Frequent Character in a String
Problem Statement:
Find and print the character that appears the most times in the given string.
If multiple characters have the same frequency, print the first one.
Example:
Input: success
Output: s
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s = [Link]();
Map<Character, Integer> freq = new LinkedHashMap<>();
for (char c : [Link]())
[Link](c, [Link](c, 0) + 1);
int max = 0;
char ans = ' ';
for (char c : [Link]()) {
if ([Link](c) > max) {
max = [Link](c);
ans = c;
}
}
[Link](ans);
}
}
📈 Q4. Student Grade Evaluation
Problem Statement:
Given marks of 5 subjects, calculate the average and print the grade based on the following
rules:
Averag Grade
e
≥ 90 A
≥ 80 B
≥ 70 C
≥ 60 D
< 60 F
Example:
Input:
90 80 70 60 50
Output:
70.0 C
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
double sum = 0;
for (int i = 0; i < 5; i++)
sum += [Link]();
double avg = sum / 5;
char grade;
if (avg >= 90) grade = 'A';
else if (avg >= 80) grade = 'B';
else if (avg >= 70) grade = 'C';
else if (avg >= 60) grade = 'D';
else grade = 'F';
[Link](avg + " " + grade);
}
}
🔢 Q5. Remove Duplicates from a Sorted Array
Problem Statement:
Given a sorted array, print all unique elements (no duplicates).
Example:
Input:
7
1 1 2 2 3 4 4
Output:
1 2 3 4
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = [Link]();
[Link](arr[0] + " ");
for (int i = 1; i < n; i++)
if (arr[i] != arr[i - 1])
[Link](arr[i] + " ");
}
}
🔁 Q6. Print Pattern of Numbers
Problem Statement:
Given an integer N, print the following pattern:
Example:
Input: 4
Output:
1
1 2
1 2 3
1 2 3 4
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
[Link](j + " ");
[Link]();
}
}
}
🔠 Q7. Count Digits, Alphabets, and Special Characters
Problem Statement:
Given a string, count how many characters are digits, alphabets, and special characters.
Example:
Input: Accenture@2025!
Output: Alphabets=9 Digits=4 Special=2
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String s = [Link]();
int alpha = 0, digit = 0, special = 0;
for (char c : [Link]()) {
if ([Link](c)) alpha++;
else if ([Link](c)) digit++;
else special++;
}
[Link]("Alphabets=" + alpha + " Digits=" + digit +
" Special=" + special);
}
}
🧮 Q8. Find Second Largest Element
Problem Statement:
Find the second largest element in an array.
Example:
Input:
5
10 20 4 45 99
Output:
45
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = [Link]();
[Link](arr);
[Link](arr[n - 2]);
}
}
🔤 Q9. Reverse Each Word in a Sentence
Problem Statement:
Reverse every word in the sentence, keeping their order intact.
Example:
Input: Accenture Coding Test
Output: erutneccA gnidoC tseT
Java Solution:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String[] words = [Link]().split(" ");
for (String w : words) {
StringBuilder sb = new StringBuilder(w);
[Link]([Link]() + " ");
}
}
}
🧩 Q10. Count Number of Words Starting with a Vowel
Problem Statement:
Given a sentence, count how many words start with a vowel.
Example:
Input: Apple is an organization
Output: 3
Java Solution:
import [Link].*;
public class Main {
static boolean startsWithVowel(String s) {
if ([Link]()) return false;
char ch = [Link]([Link](0));
return "aeiou".indexOf(ch) != -1;
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String[] words = [Link]().trim().split("\\s+");
int count = 0;
for (String w : words)
if (startsWithVowel(w)) count++;
[Link](count);
}
}
✅ Summary of Set 5 (Final Level)
# Problem Concept Difficulty
1 Validate ID Regex Medium
2 Even sum & odd product Loops Easy
3 Most frequent char HashMap Medium
4 Student grading Conditional logic Medium
5 Remove duplicates Arrays Easy
6 Pattern printing Nested loops Easy
7 Count char types Classification Easy
8 Second largest Sorting Easy
9 Reverse words StringBuilder Medium