Accenture Coding Questions from the Last Month: Frequently Asked Coding Questions and Solutions

Accenture Most Asked Coding Questions with Python Solutions

In this blog, we will walk through some of the most frequently asked coding questions in Accenture’s placement exams and technical interviews. Each question is followed by a detailed explanation and a Python 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 face. Mastering them will improve your coding skills and boost your confidence for technical interviews.

Accenture Placement Materials Link : Click Here

1) 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
Binary of 15 is 1111, so the sum is 4.

#CODE

def binary_sum(n):
return bin(n).count(‘1’)

n = 15
print(“Sum of binary digits:”, binary_sum(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

Python Solution:

 

def second_smallest(arr):
unique_sorted = sorted(set(arr))
return unique_sorted[1] if len(unique_sorted) > 1 else None

arr = [3, 1, 4, 1, 5]
print(“Second smallest element:”, second_smallest(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

Python Solution:

 

def shorten_word(word):
return word[0] + str(len(word[1:-1])) + word[-1]

word = “examination”
print(“Shortened word:”, shorten_word(word))

4) Prime Numbers Between 1 and N

Problem Statement:
Print all prime numbers between 1 and N.

Python Solution:

 

def is_prime(num):
if num < 2:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True

def primes_upto_n(n):
return [i for i in range(2, n+1) if is_prime(i)]

n = 50
print(“Prime numbers up to”, n, “:”, primes_upto_n(n))

5) Print Floyd’s Triangle

Problem Statement:
Print Floyd’s triangle with N rows.

Example:
Input: N = 5

Python Solution:

 

def floyd_triangle(n):
num = 1
for i in range(1, n+1):
for j in range(i):
print(num, end=” “)
num += 1
print()

rows = 5
floyd_triangle(rows)

6) Check Leap Year

Problem Statement:
Write a program to check if a given year is a leap year or not.

Python Solution:

 

def is_leap_year(year):
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
return True
return False

year = 2024
print(year, “is a leap year?” , is_leap_year(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.

Python Solution:

 

def sum_even_odd(arr):
even_sum = sum(x for x in arr if x % 2 == 0)
odd_sum = sum(x for x in arr if x % 2 != 0)
return even_sum, odd_sum

arr = [1, 2, 3, 4, 5, 6]
even_sum, odd_sum = sum_even_odd(arr)
print(“Even sum:”, even_sum)
print(“Odd sum:”, odd_sum)

8) Vowel Permutation

Problem Statement:
Given a string, print all possible permutations of the vowels present in the string.

Python Solution:

 

from itertools import permutations

def vowel_permutations(s):
vowels = [char for char in s if char in ‘aeiou’]
return list(permutations(vowels))

word = “accenture”
print(“Vowel permutations:”, vowel_permutations(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.

Python Solution:

 

def reverse_and_positions(arr):
arr.reverse()
even_pos = arr[1::2]
odd_pos = arr[0::2]
return “Even positions: ” + str(even_pos) + “, Odd positions: ” + str(odd_pos)

arr = [10, 20, 30, 40, 50]
print(reverse_and_positions(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.

Python Solution:

 

def winning_team(teams, goals):
max_goals = max(goals)
winner_index = goals.index(max_goals)
return teams[winner_index]

teams = [“Team A”, “Team B”, “Team C”, “Team D”, “Team E”]
goals = [5, 2, 3, 1, 4]
print(“Winning team:”, winning_team(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.

Python Solution:

 

def max_chocolates(prices):
free_chocolates = sum(1 for price in prices if price % 5 == 0)
return free_chocolates

chocolate_prices = [10, 15, 20, 25, 7, 9]
print(“Maximum chocolates you can buy:”, max_chocolates(chocolate_prices))

Conclusion

These coding questions reflect the types of problems that Accenture frequently asks in its coding interviews and placement exams. Make sure to practice them and understand the logic behind each problem. By mastering these problems, you’ll enhance your problem-solving skills and be better prepared for the Accenture technical interviews.

 

Leave a Reply

Your email address will not be published. Required fields are marked *