Back

Accenture Coding Questions and Answers With Important Topics

22 Oct 2024
5 min read

Preparing for coding tests at Accenture can be challenging, but with the right preparation, you can improve your chances of success. This guide will cover Accenture coding questions, highlight the type of questions asked, and provide tips to help you perform well in coding rounds.

Accenture Coding Test Syllabus

Here is the Accenture coding test syllabus that you might encounter in technical assessment or interview:

  • Basics of Programming
  • Input and  Output Concepts
  • Flow Control
  • Conditional Looping
  • Arrays
  • Strings
  • Linked Lists
  • Stacks and Queues
  • Trees
  • Graphs
  • Dynamic Programming
  • Sorting and Searching
  • Backtracking

Accenture Coding Questions Section Overview

Duration: 45 minutes.

Number of Questions: Typically 2 coding problems.

Difficulty Level: Easy - Medium.

Languages Allowed: C, C++, Java, Python.

Rules for Accenture Coding Questions

Here, are the rules to be followed while answering accenture coding questions:

  • You must write the entire program without any pre-existing code.
  • You need to write the code for the given problem statements. Once done, run the program to see the output.
  •  If there are any errors in your code, they will be displayed to help you debug.
  • To pass this section, you typically need one clear output and one partial output.

Accenture Coding Questions and Answers

Accenture often uses a variety of coding challenges to test your problem-solving skills. Here’s a list of 10 Accenture coding questions:

1. In a race, each participant's finish time is recorded. You need to find out who finished first and how long it took them. Additionally, you need to find the average finish time of all participants.

Input Format

  • A list of floating-point numbers representing finish times.

Output Format

  • Two floating-point numbers: the first-place time and the average time.

Example

Input: [12.5, 10.0, 11.2, 13.3]
Output: (10.0, 11.5)

Python

def race_results(times):
    if not times:
        return None, 0

    first_place_time = min(times)
    average_time = sum(times) / len(times)
    return first_place_time, average_time

# Example usage
print(race_results([12.5, 10.0, 11.2, 13.3]))  # Output: (10.0, 11.5)

Java

public class Main {
    public static double[] raceResults(double[] times) {
        if (times.length == 0) return new double[]{-1, 0};

        double firstPlaceTime = times[0];
        double totalTime = 0;
        
        for (double time : times) {
            if (time < firstPlaceTime) firstPlaceTime = time;
            totalTime += time;
        }
        
        double averageTime = totalTime / times.length;
        return new double[]{firstPlaceTime, averageTime};
    }

    public static void main(String[] args) {
        double[] results = raceResults(new double[]{12.5, 10.0, 11.2, 13.3});
        System.out.println("First Place Time: " + results[0] + ", Average Time: " + results[1]);
    }
}

C

#include <stdio.h>

void raceResults(double times[], int size, double* firstPlace, double* average) {
    if (size == 0) {
        *firstPlace = -1;
        *average = 0;
        return;
    }

    *firstPlace = times[0];
    double totalTime = 0;

    for (int i = 0; i < size; i++) {
        if (times[i] < *firstPlace) *firstPlace = times[i];
        totalTime += times[i];
    }

    *average = totalTime / size;
    }

int main() {
    double times[] = {12.5, 10.0, 11.2, 13.3};
    double firstPlace, average;
    raceResults(times, 4, &firstPlace, &average);
    printf("First Place Time: %.2f, Average Time: %.2f\n", firstPlace, average);
    return 0;
}

2. In a magical forest, each animal has a unique identifier (ID). Some animals have decided to form pairs based on their IDs. Your task is to find all the unique pairs of animal IDs that can be formed.

Input Format

  • A list of integers representing animal IDs.

Output Format

  • A list of unique pairs of animal IDs.
Input: [1, 2, 3]
Output: [(1, 2), (1, 3), (2, 3)]

Python

def unique_pairs(animal_ids):
    pairs = []
    for i in range(len(animal_ids)):
        for j in range(i + 1, len(animal_ids)):
            pairs.append((animal_ids[i], animal_ids[j]))
    return pairs

# Example usage
print(unique_pairs([1, 2, 3]))  # Output: [(1, 2), (1, 3), (2, 3)]

Java

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<int[]> uniquePairs(int[] animalIds) {
        List<int[]> pairs = new ArrayList<>();
        for (int i = 0; i < animalIds.length; i++) {
            for (int j = i + 1; j < animalIds.length; j++) {
                pairs.add(new int[]{animalIds[i], animalIds[j]});
            }
        }
        return pairs;
    }

    public static void main(String[] args) {
        List<int[]> result = uniquePairs(new int[]{1, 2, 3});
        for (int[] pair : result) {
            System.out.println("Pair: " + pair[0] + ", " + pair[1]);
        }
    }
}

C

#include <stdio.h>

void uniquePairs(int animalIds[], int size) {
    for (int i = 0; i < size; i++) {
        for (int j = i + 1; j < size; j++) {
            printf("Pair: %d, %d\n", animalIds[i], animalIds[j]);
        }
    }
}

int main() {
    int animalIds[] = {1, 2, 3};
    uniquePairs(animalIds, 3);
    return 0;
}
₹ 49,000
strip
₹ 33,000
/-
Karthik was able to transform his career from a boring job to an exciting job in software!
Talk to a career expert
intensive student
emoji

3. In a small village, there are treasure chests scattered around. Each chest has a certain number of coins, and some chests have been cursed, causing them to give negative coins. Your task is to find the maximum sum of coins you can collect from a consecutive series of chests.

Input Format

  • A list of integers representing the coins in each chest.

Output Format

  • An integer representing the maximum sum of coins from consecutive chests.

Example

Input: [2, -3, 4, -1, 2, 1, -5, 4]
Output: 6

Python

def max_treasure(chests):
    max_sum = current_sum = 0
    for coins in chests:
        current_sum += coins
        if current_sum < 0:
            current_sum = 0
        max_sum = max(max_sum, current_sum)
    return max_sum

# Example usage
print(max_treasure([2, -3, 4, -1, 2, 1, -5, 4]))  # Output: 6

Java

public class Main {
    public static int maxTreasure(int[] chests) {
        int maxSum = 0, currentSum = 0;
        for (int coins : chests) {
            currentSum += coins;
            if (currentSum < 0) currentSum = 0;
            maxSum = Math.max(maxSum, currentSum);
        }
        return maxSum;
    }

    public static void main(String[] args) {
        System.out.println(maxTreasure(new int[]{2, -3, 4, -1, 2, 1, -5, 4}));  // Output: 6
    }
}

C

#include <stdio.h>

int maxTreasure(int chests[], int size) {
    int maxSum = 0, currentSum = 0;
    for (int i = 0; i < size; i++) {
        currentSum += chests[i];
        if (currentSum < 0) currentSum = 0;
        if (currentSum > maxSum) maxSum = currentSum;
    }
    return maxSum;
}

int main() {
    int chests[] = {2, -3, 4, -1, 2, 1, -5, 4};
    printf("%d\n", maxTreasure(chests, 8));  // Output: 6
    return 0;
}

4. The royal baker needs to prepare a special cake. Each ingredient has a specific weight. The baker wants to know the total weight of the ingredients and the heaviest ingredient used.

Input Format

  • A list of floating-point numbers representing the weights of the ingredients.

Output Format

  • Two floating-point numbers: the total weight and the heaviest ingredient.

Example

Input: [1.2, 0.5, 2.3, 1.8]
Output: (5.8, 2.3)

Python

def cake_ingredients(weights):
    if not weights:
        return 0, 0

    total_weight = sum(weights)
    heaviest = max(weights)
    return total_weight, heaviest

# Example usage
print(cake_ingredients([1.2, 0.5, 2.3, 1.8]))  # Output: (5.8, 2.3)

Java

public class Main {
    public static double[] cakeIngredients(double[] weights) {
        if (weights.length == 0) return new double[]{0, 0};

        double totalWeight = 0;
        double heaviest = weights[0];
        
        for (double weight : weights) {
            totalWeight += weight;
            if (weight > heaviest) heaviest = weight;
        }
        
        return new double[]{totalWeight, heaviest};
    }

    public static void main(String[] args) {
        double[] results = cakeIngredients(new double[]{1.2, 0.5, 2.3, 1.8});
        System.out.println("Total Weight: " + results[0] + ", Heaviest Ingredient: " + results[1]);
    }
}

C

#include <stdio.h>

void cakeIngredients(double weights[], int size, double* totalWeight, double* heaviest) {
    if (size == 0) {
        *totalWeight = 0;
        *heaviest = 0;
        return;
    }

    *totalWeight = 0;
    *heaviest = weights[0];

    for (int i = 0; i < size; i++) {
        *totalWeight += weights[i];
        if (weights[i] > *heaviest) *heaviest = weights[i];
    }
}

int main() {
    double weights[] = {1.2, 0.5, 2.3, 1.8};
    double totalWeight, heaviest;
    cakeIngredients(weights, 4, &totalWeight, &heaviest);
    printf("Total Weight: %.2f, Heaviest Ingredient: %.2f\n", totalWeight, heaviest);
    return 0;
}

5. In an enchanted garden, flowers bloom in various colors, and each color has a specific point value. Your task is to calculate the total points based on the flowers picked by a gardener.

Input Format

  • A list of integers representing the points for each flower.

Output Format

  • An integer representing the total points earned from the flowers.

Example

Input: [5, 3, 8, 2]
Output: 18

Python

def total_flower_points(flowers):
    total_points = 0
    for points in flowers:
        total_points += points
    return total_points

if __name__ == "__main__":
    print(total_flower_points([5, 3, 8, 2]))  # Output: 18

Java

public class Main {
    public static int totalFlowerPoints(int[] flowers) {
        int totalPoints = 0;
        for (int points : flowers) {
            totalPoints += points;
        }
        return totalPoints;
    }

    public static void main(String[] args) {
        System.out.println(totalFlowerPoints(new int[]{5, 3, 8, 2}));  // Output: 18
    }
}

C

#include <stdio.h>

int totalFlowerPoints(int flowers[], int size) {
    int totalPoints = 0;
    for (int i = 0; i < size; i++) {
        totalPoints += flowers[i];
    }
    return totalPoints;
}

int main() {
    int flowers[] = {5, 3, 8, 2};
    printf("%d\n", totalFlowerPoints(flowers, 4));  // Output: 18
    return 0;
}

6. A time traveler collects artifacts from different years. Each artifact has a year associated with it. Your task is to find the range of years from the earliest to the latest artifact collected.

Input Format

  • A list of integers representing the years.

Output Format

  • An integer representing the range of years (latest year - earliest year).
Input: [1995, 2001, 1985, 2010]
Output: 25

Python

def year_range(artifacts):
    return max(artifacts) - min(artifacts)

# Example usage
print(year_range([1995, 2001, 1985, 2010]))  # Output: 25

Java

public class Main {
    public static int yearRange(int[] artifacts) {
        int minYear = artifacts[0];
        int maxYear = artifacts[0];
        
        for (int year : artifacts) {
            if (year < minYear) minYear = year;
            if (year > maxYear) maxYear = year;
        }
        
        return maxYear - minYear;
    }

    public static void main(String[] args) {
        System.out.println(yearRange(new int[]{1995, 2001, 1985, 2010}));  // Output: 25
    }
}

C

#include <stdio.h>

int yearRange(int artifacts[], int size) {
    int minYear = artifacts[0];
    int maxYear = artifacts[0];
    
    for (int i = 1; i < size; i++) {
        if (artifacts[i] < minYear) minYear = artifacts[i];
        if (artifacts[i] > maxYear) maxYear = artifacts[i];
    }
    
    return maxYear - minYear;
}

int main() {
    int artifacts[] = {1995, 2001, 1985, 2010};
    printf("%d\n", yearRange(artifacts, 4));  // Output: 25
    return 0;
}
₹ 49,000
strip
₹ 33,000
/-
Karthik was able to transform his career from a boring job to an exciting job in software!
Talk to a career expert
intensive student
emoji

7. In a mysterious library, each book has a unique ID, and some books are quite old. Your task is to find the ID of the oldest book and the average ID of all the books.

Input Format

  • A list of integers representing book IDs.

Output Format

  • Two integers: the ID of the oldest book and the average ID (rounded down)

Example

Input: [1001, 1002, 999, 1003]
Output: (999, 1001)

Python

def book_info(books):
    oldest = min(books)
    average = sum(books) // len(books)
    return oldest, average

# Example usage
print(book_info([1001, 1002, 999, 1003]))  # Output: (999, 1001)

Java

public class Main {
    public static int[] bookInfo(int[] books) {
        int oldest = books[0];
        int total = 0;
        
        for (int id : books) {
            if (id < oldest) oldest = id;
            total += id;
        }
        
        int average = total / books.length;
        return new int[]{oldest, average};
    }

    public static void main(String[] args) {
        int[] result = bookInfo(new int[]{1001, 1002, 999, 1003});
        System.out.println("(" + result[0] + ", " + result[1] + ")");  // Output: (999, 1001)
    }
}

C

#include <stdio.h>

void bookInfo(int books[], int size, int* oldest, int* average) {
    *oldest = books[0];
    int total = 0;

    for (int i = 0; i < size; i++) {
        if (books[i] < *oldest) *oldest = books[i];
        total += books[i];
    }

    *average = total / size;
}

int main() {
    int books[] = {1001, 1002, 999, 1003};
    int oldest, average;
    bookInfo(books, 4, &oldest, &average);
    printf("Oldest ID: %d, Average ID: %d\n", oldest, average);  // Output: (999, 1001)
    return 0;
}

8. A dragon hoards treasures in different forms, each with a specific value. Your task is to calculate the total value of the treasures and find the highest value among them.

Input Format

  • A list of integers representing the values of the treasures.

Output Format

  • Two integers: the total value and the highest value.

Example

Input: [200, 500, 1000, 300]
Output: (2000, 1000)

Python

def dragon_hoard(treasures):
    total_value = sum(treasures)
    highest_value = max(treasures)
    return total_value, highest_value
# Example usage
print(dragon_hoard([200, 500, 1000, 300]))  # Output: (2000, 1000)

Java

public class Main {
    public static int[] dragonHoard(int[] treasures) {
        int totalValue = 0;
        int highestValue = treasures[0];
        
        for (int value : treasures) {
            totalValue += value;
            if (value > highestValue) highestValue = value;
        }
        
        return new int[]{totalValue, highestValue};
    }

    public static void main(String[] args) {
        int[] result = dragonHoard(new int[]{200, 500, 1000, 300});
        System.out.println("(" + result[0] + ", " + result[1] + ")");  // Output: (2000, 1000)
    }
}

C

#include <stdio.h>

void dragonHoard(int treasures[], int size, int* totalValue, int* highestValue) {
    *totalValue = 0;
    *highestValue = treasures[0];

    for (int i = 0; i < size; i++) {
        *totalValue += treasures[i];
        if (treasures[i] > *highestValue) *highestValue = treasures[i];
    }
}

int main() {
    int treasures[] = {200, 500, 1000, 300};
    int totalValue, highestValue;
    dragonHoard(treasures, 4, &totalValue, &highestValue);
    printf("Total Value: %d, Highest Value: %d\n", totalValue, highestValue);  // Output: (2000, 1000)
    return 0;
}

9. A wizard brews a secret potion using various magical ingredients, each represented by a unique integer ID. Your task is to identify if a specific ingredient ID is used in the potion.

Input Format

  • A list of integers representing the ingredient IDs and an integer representing the ID to check.

Output Format

  • A string indicating whether the ingredient ID is used ("Yes" or "No").

Example

Input: [101, 102, 103, 104], 102
Output: Yes

Python

def check_ingredient(ingredients, id_to_check):
    return "Yes" if id_to_check in ingredients else "No"

# Example usage
print(check_ingredient([101, 102, 103, 104], 102))  # Output: Yes

Java

import java.util.Arrays;

public class Main {
    public static String checkIngredient(int[] ingredients, int idToCheck) {
        return Arrays.stream(ingredients).anyMatch(id -> id == idToCheck) ? "Yes" : "No";
    }

    public static void main(String[] args) {
        System.out.println(checkIngredient(new int[]{101, 102, 103, 104}, 102));  // Output: Yes
    }
}

C

#include <stdio.h>

const char* checkIngredient(int ingredients[], int size, int idToCheck) {
    for (int i = 0; i < size; i++) {
        if (ingredients[i] == idToCheck) {
            return "Yes";
        }
    }
    return "No";
}

int main() {
    int ingredients[] = {101, 102, 103, 104};
    printf("%s\n", checkIngredient(ingredients, 4, 102));  // Output: Yes
    return 0;
}

10. A timekeeper has a collection of clocks, each representing a specific hour. Your task is to calculate the total hours represented by the clocks and find the clock showing the highest hour.

Input Format

  • A list of integers representing the hours of the clocks.

Output Format

  • Two integers: the total hours and the highest hour.

Example

Input: [3, 7, 5, 9]
Output: (24, 9)

Python

def timekeeper_clocks(clocks):
    total_hours = sum(clocks)
    highest_hour = max(clocks)
    return total_hours, highest_hour

# Example usage
print(timekeeper_clocks([3, 7, 5, 9]))  # Output: (24, 9)

Java

public class Main {
    public static int[] timekeeperClocks(int[] clocks) {
        int totalHours = 0;
        int highestHour = clocks[0];
        
        for (int hour : clocks) {
            totalHours += hour;
            if (hour > highestHour) highestHour = hour;
        }
        
        return new int[]{totalHours, highestHour};
    }

    public static void main(String[] args) {
        int[] result = timekeeperClocks(new int[]{3, 7, 5, 9});
        System.out.println("(" + result[0] + ", " + result[1] + ")");  // Output: (24, 9)
    }
}

C

#include <stdio.h>

void timekeeperClocks(int clocks[], int size, int* totalHours, int* highestHour) {
    *totalHours = 0;
    *highestHour = clocks[0];

    for (int i = 0; i < size; i++) {
        *totalHours += clocks[i];
        if (clocks[i] > *highestHour) *highestHour = clocks[i];
    }
}

int main() {
    int clocks[] = {3, 7, 5, 9};
    int totalHours, highestHour;
    timekeeperClocks(clocks, 4, &totalHours, &highestHour);
    printf("Total Hours: %d, Highest Hour: %d\n", totalHours, highestHour);  // Output: (24, 9)
    return 0;
}

Tips for Cracking Accenture Coding Rounds

To excel in the Accenture coding assessment, consider these helpful tips:

  • Use coding platforms like LeetCode, HackerRank, or CodeSignal to work on problems similar to Accenture's previous year's coding questions.
  • Ensure you have a solid understanding of data structures and algorithms, as many questions will test these skills.
  • Focus on writing code that is easy to read and understand. Use clear names for variables and add comments when necessary.
  • Think about how to make your code faster and use less memory. Understanding time and space complexity is crucial.
  • Practice with friends or use online platforms to simulate real interview conditions, helping you get comfortable under pressure.

Conclusion

In conclusion, preparing for Accenture coding questions requires a mix of theoretical knowledge and practical coding skills. By knowing the types of questions commonly asked and practicing consistently, you can increase your chances of doing well in the coding rounds.

₹ 49,000
strip
₹ 33,000
/-
Karthik was able to transform his career from a boring job to an exciting job in software!
Talk to a career expert
intensive student
emoji

Frequently Asked Questions

1. What is pseudo code and why is it used in Accenture coding assessments?

Pseudo code is a simple way to describe an algorithm using the structure of programming languages without worrying about syntax. It helps assess your logical thinking and problem-solving skills.

2. Are there any specific Accenture ASE coding questions I should know about?

Accenture ASE coding questions usually focus on programming basics and may include topics related to automation and testing, along with general coding challenges.

Read More Articles

Chat with us
Chat with us
Talk to career expert