Table of Contents
10 Accenture Coding Questions With Proven Solutions (2024). In the competitive landscape of technical job interviews, coding assessments serve as crucial gatekeepers to prestigious positions. For aspiring developers seeking opportunities at Accenture, one of the world’s leading professional services companies, mastering the most commonly asked coding questions is essential. This article aims to provide an in-depth exploration of the top 10 frequently asked coding questions in the Accenture exam, along with comprehensive solutions in Python, C++, and Java. Accenture Coding Questions With Proven Solutions. if you love AI then click Here
10 Accenture Coding Questions With Proven Solutions (2024)
1. FizzBuzz
Question: Write a program that prints the numbers from 1 to 100. But for multiples of three, print “Fizz” instead of the number, and for the multiples of five, print “Buzz”. For numbers that are multiples of both three and five, print “FizzBuzz”.
Python Solution:
def fizzbuzz():
for i in range(1, 101):
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
fizzbuzz()
C++ Solution:
#include <iostream>
using namespace std;
void fizzbuzz() {
for (int i = 1; i <= 100; ++i) {
if (i % 3 == 0 && i % 5 == 0)
cout << "FizzBuzz" << endl;
else if (i % 3 == 0)
cout << "Fizz" << endl;
else if (i % 5 == 0)
cout << "Buzz" << endl;
else
cout << i << endl;
}
}
int main() {
fizzbuzz();
return 0;
}
Java Solution:
public class FizzBuzz {
public static void fizzbuzz() {
for (int i = 1; i <= 100; ++i) {
if (i % 3 == 0 && i % 5 == 0)
System.out.println("FizzBuzz");
else if (i % 3 == 0)
System.out.println("Fizz");
else if (i % 5 == 0)
System.out.println("Buzz");
else
System.out.println(i);
}
}
public static void main(String[] args) {
fizzbuzz();
}
}
2. Palindrome Check
Question: Write a function to determine if a given string is a palindrome.
Python Solution:
def is_palindrome(s):
return s == s[::-1]
# Test the function
print(is_palindrome("racecar")) # Output: True
print(is_palindrome("hello")) # Output: False
C++ Solution:
#include <iostream>
#include <string>
using namespace std;
bool is_palindrome(string s) {
int i = 0, j = s.length() - 1;
while (i < j) {
if (s[i] != s[j])
return false;
++i;
--j;
}
return true;
}
int main() {
cout << boolalpha << is_palindrome("racecar") << endl; // Output: true
cout << boolalpha << is_palindrome("hello") << endl; // Output: false
return 0;
}
Java Solution:
public class PalindromeCheck {
public static boolean isPalindrome(String s) {
int i = 0, j = s.length() - 1;
while (i < j) {
if (s.charAt(i) != s.charAt(j))
return false;
++i;
--j;
}
return true;
}
public static void main(String[] args) {
System.out.println(isPalindrome("racecar")); // Output: true
System.out.println(isPalindrome("hello")); // Output: false
}
}
3. Fibonacci Series:
Question: Write a function to generate the Fibonacci sequence up to a specified number of terms.
Python Solution:
def fibonacci(n):
fib_sequence = [0, 1]
while len(fib_sequence) < n:
fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
return fib_sequence
# Test the function
print(fibonacci(10)) # Output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
C++ Solution:
#include <iostream>
#include <vector>
using namespace std;
vector<int> fibonacci(int n) {
vector<int> fib_sequence;
fib_sequence.push_back(0);
fib_sequence.push_back(1);
while (fib_sequence.size() < n) {
int next_fib = fib_sequence[fib_sequence.size() - 1] + fib_sequence[fib_sequence.size() - 2];
fib_sequence.push_back(next_fib);
}
return fib_sequence;
}
int main() {
vector<int> result = fibonacci(10);
for (int num : result) {
cout << num << " ";
}
cout << endl;
return 0;
}
Java Solution:
import java.util.ArrayList;
import java.util.List;
public class Fibonacci {
public static List<Integer> fibonacci(int n) {
List<Integer> fibSequence = new ArrayList<>();
fibSequence.add(0);
fibSequence.add(1);
while (fibSequence.size() < n) {
int nextFib = fibSequence.get(fibSequence.size() - 1) + fibSequence.get(fibSequence.size() - 2);
fibSequence.add(nextFib);
}
return fibSequence;
}
public static void main(String[] args) {
List<Integer> result = fibonacci(10);
for (int num : result) {
System.out.print(num + " ");
}
System.out.println();
}
}
4. Factorial Calculation
Question: Write a function to calculate the factorial of a given number.
Python Solution:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
# Test the function
print(factorial(5)) # Output: 120
C++ Solution:
#include <iostream>
using namespace std;
int factorial(int n) {
if (n == 0)
return 1;
else
return n * factorial(n - 1);
}
int main() {
cout << factorial(5) << endl; // Output: 120
return 0;
}
Java Solution:
public class Factorial {
public static int factorial(int n) {
if (n == 0)
return 1;
else
return n * factorial(n - 1);
}
public static void main(String[] args) {
System.out.println(factorial(5)); // Output: 120
}
}
Top 10 Accenture Coding Questions and Solutions
5. Binary Search
Question: Implement the binary search algorithm to find the index of a given element in a sorted array.
Python Solution:
def binary_search(arr, target):
left, right = 0, len(arr) - 1
while left <= right:
mid = left + (right - left) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
left = mid + 1
else:
right = mid - 1
return -1
# Test the function
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
target = 6
print(binary_search(arr, target)) # Output: 5 (Index of 6 in the array)
C++ Solution:
#include <iostream>
#include <vector>
using namespace std;
int binary_search(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;
else if (arr[mid] < target)
left = mid + 1;
else
right = mid - 1;
}
return -1;
}
int main() {
vector<int> arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int target = 6;
cout << binary_search(arr, target) << endl; // Output: 5 (Index of 6 in the array)
return 0;
}
Java Solution:
import java.util.Arrays;
public class BinarySearch {
public static int binarySearch(int[] arr, int target) {
int left = 0, right = arr.length - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (arr[mid] == target)
return mid;
else if (arr[mid] < target)
left = mid + 1;
else
right = mid - 1;
}
return -1;
}
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int target = 6;
System.out.println(binarySearch(arr, target)); // Output: 5 (Index of 6 in the array)
}
}
6. Reverse a String
Question: Write a function to reverse a given string.
Python Solution:
def reverse_string(s):
return s[::-1]
# Test the function
print(reverse_string("hello")) # Output: "olleh"
C++ Solution:
#include <iostream>
#include <string>
using namespace std;
string reverse_string(string s) {
string reversed;
for (int i = s.length() - 1; i >= 0; --i) {
reversed.push_back(s[i]);
}
return reversed;
}
int main() {
cout << reverse_string("hello") << endl; // Output: "olleh"
return 0;
}
Java Solution:
public class ReverseString {
public static String reverseString(String s) {
StringBuilder reversed = new StringBuilder();
for (int i = s.length() - 1; i >= 0; --i) {
reversed.append(s.charAt(i));
}
return reversed.toString();
}
public static void main(String[] args) {
System.out.println(reverseString("hello")); // Output: "olleh"
}
}
Top 10 Accenture Coding Questions and Solutions
7. Check Prime Number
Question: Write a function to check whether a given number is prime or not.
Python Solution:
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
# Test the function
print(is_prime(11)) # Output: True
print(is_prime(15)) # Output: False
C++ Solution:
#include <iostream>
#include <cmath>
using namespace std;
bool is_prime(int n) {
if (n <= 1)
return false;
for (int i = 2; i <= sqrt(n); ++i) {
if (n % i == 0)
return false;
}
return true;
}
int main() {
cout << boolalpha << is_prime(11) << endl; // Output: true
cout << boolalpha << is_prime(15) << endl; // Output: false
return 0;
}
Java Solution:
public class PrimeCheck {
public static boolean isPrime(int n) {
if (n <= 1)
return false;
for (int i = 2; i <= Math.sqrt(n); ++i) {
if (n % i == 0)
return false;
}
return true;
}
public static void main(String[] args) {
System.out.println(isPrime(11)); // Output: true
System.out.println(isPrime(15)); // Output: false
}
}
Top 10 Coding FAQs in the Accenture Exam
8. Count Characters in a String
Question: Write a function to count the occurrences of each character in a given string.
Python Solution:
def count_characters(s):
char_count = {}
for char in s:
char_count[char] = char_count.get(char, 0) + 1
return char_count
# Test the function
print(count_characters("hello")) # Output: {'h': 1, 'e': 1, 'l': 2, 'o': 1}
C++ Solution:
#include <iostream>
#include <unordered_map>
using namespace std;
unordered_map<char, int> count_characters(string s) {
unordered_map<char, int> charCount;
for (char c : s) {
++charCount[c];
}
return charCount;
}
int main() {
auto charCount = count_characters("hello");
for (auto pair : charCount) {
cout << pair.first << ": " << pair.second << endl;
}
return 0;
}
Java Solution:
import java.util.HashMap;
import java.util.Map;
public class CharacterCount {
public static Map<Character, Integer> countCharacters(String s) {
Map<Character, Integer> charCount = new HashMap<>();
for (char c : s.toCharArray()) {
charCount.put(c, charCount.getOrDefault(c, 0) + 1);
}
return charCount;
}
public static void main(String[] args) {
Map<Character, Integer> charCount = countCharacters("hello");
for (Map.Entry<Character, Integer> entry : charCount.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
}
Top 10 Accenture Coding Questions and Solutions
9. Merge Sorted Arrays
Question: Write a function to merge two sorted arrays into a single sorted array.
Python Solution:
def merge_sorted_arrays(arr1, arr2):
merged = []
i, j = 0, 0
while i < len(arr1) and j < len(arr2):
if arr1[i] < arr2[j]:
merged.append(arr1[i])
i += 1
else:
merged.append(arr2[j])
j += 1
merged.extend(arr1[i:])
merged.extend(arr2[j:])
return merged
# Test the function
print(merge_sorted_arrays([1, 3, 5], [2, 4, 6])) # Output: [1, 2, 3, 4, 5, 6]
C++ Solution:
#include <iostream>
#include <vector>
using namespace std;
vector<int> merge_sorted_arrays(const vector<int>& arr1, const vector<int>& arr2) {
vector<int> merged;
int i = 0, j = 0;
while (i < arr1.size() && j < arr2.size()) {
if (arr1[i] < arr2[j])
merged.push_back(arr1[i++]);
else
merged.push_back(arr2[j++]);
}
while (i < arr1.size())
merged.push_back(arr1[i++]);
while (j < arr2.size())
merged.push_back(arr2[j++]);
return merged;
}
int main() {
vector<int> arr1 = {1, 3, 5};
vector<int> arr2 = {2, 4, 6};
vector<int> merged = merge_sorted_arrays(arr1, arr2);
for (int num : merged) {
cout << num << " ";
}
cout << endl;
return 0;
}
Java Solution:
import java.util.ArrayList;
import java.util.List;
public class MergeSortedArrays {
public static List<Integer> mergeSortedArrays(List<Integer> arr1, List<Integer> arr2) {
List<Integer> merged = new ArrayList<>();
int i = 0, j = 0;
while (i < arr1.size() && j < arr2.size()) {
if (arr1.get(i) < arr2.get(j))
merged.add(arr1.get(i++));
else
merged.add(arr2.get(j++));
}
while (i < arr1.size())
merged.add(arr1.get(i++));
while (j < arr2.size())
merged.add(arr2.get(j++));
return merged;
}
public static void main(String[] args) {
List<Integer> arr1 = List.of(1, 3, 5);
List<Integer> arr2 = List.of(2, 4, 6);
List<Integer> merged = mergeSortedArrays(arr1, arr2);
for (int num : merged) {
System.out.print(num + " ");
}
System.out.println();
}
}
10. Remove Duplicates from Sorted Array
Question: Write a function to remove duplicates from a sorted array in-place such that each unique element appears only once and returns the new length.
Python Solution:
def remove_duplicates(nums):
if not nums:
return 0
i = 0
for j in range(1, len(nums)):
if nums[j] != nums[i]:
i += 1
nums[i] = nums[j]
return i + 1
# Test the function
nums = [1, 1, 2, 2, 3, 4, 4, 5]
length = remove_duplicates(nums)
print(length) # Output: 5 (New length of the array)
C++ Solution:
#include <iostream>
#include <vector>
using namespace std;
int removeDuplicates(vector<int>& nums) {
if (nums.empty())
return 0;
int i = 0;
for (int j = 1; j < nums.size(); ++j) {
if (nums[j] != nums[i]) {
++i;
nums[i] = nums[j];
}
}
return i + 1;
}
int main() {
vector<int> nums = {1, 1, 2, 2, 3, 4, 4, 5};
int length = removeDuplicates(nums);
cout << length << endl; // Output: 5 (New length of the array)
return 0;
}
Java Solution:
import java.util.Arrays;
public class RemoveDuplicates {
public static int removeDuplicates(int[] nums) {
if (nums.length == 0)
return 0;
int i = 0;
for (int j = 1; j < nums.length; ++j) {
if (nums[j] != nums[i]) {
++i;
nums[i] = nums[j];
}
}
return i + 1;
}
public static void main(String[] args) {
int[] nums = {1, 1, 2, 2, 3, 4, 4, 5};
int length = removeDuplicates(nums);
System.out.println(length); // Output: 5 (New length of the array)
}
}
Conclusion
Accenture Coding Questions With Proven Solutions. Mastering the top 10 frequently asked coding questions in the Accenture exam can significantly enhance your chances of success in the interview process. Through this article, we have explored various fundamental algorithms and data structures, providing solutions in Python, C++, and Java. By understanding these concepts and practicing regularly, you can confidently tackle coding assessments and secure rewarding opportunities at Accenture or any other esteemed organization. Happy coding! if you are looking for a job. please visit Here