Home Paper Accenture Coding Questions for Placements

Accenture Coding Questions for Placements

by Adarsh Pal
65 minutes read
  • In Accenture there will be 2 or 3 coding questions that you have to solve in 45 minutes.
  • In the Accenture Coding Round ,you can write coding using in these preferred language:-
    a. C
    b. C++
    c. Java
    d. Python

The difficulty level of the questions are medium. You have to practice a lot to get a good score in the Accenture coding Questions.

Rules for Accenture Coding Questions Section

  1. Two questions will be asked. You’ve to solve both the questions in 45 minutes.
  2. You must start your code from scratch.
  3. The Coding section is divided into two, first for writing the code and the other for the output. So you should write the whole program.
  4. Errors are clearly displayed.

Accenture Coding Questions With Solutions 2021, 2022 & 2023

Problem Statement 1

Write a function SmallLargeSum(array) which accepts the array as an argument or parameter, that performs the addition of the second largest element from the even location with the second largest element from an odd location?


Rules:
a. All the array elements are unique.
b. If the length of the array is 3 or less than 3, then return 0.
c. If Array is empty then return zero.

Sample Test Case 1:
Input:
6
3 2 1 7 5 4
Output:
7

Explanation: The second largest element in the even locations (3, 1, 5) is 3. The second largest element in the odd locations (2, 7, 4) is 4. So the addition of 3 and 4 is 7. So the answer is 7.

Sample Test Case 2:
Input:
7
4 0 7 9 6 4 2
Output:
10

Solution:

  • First we’ve to take input from the user i.e in the main function.
  • Then we’ve to create two different arrays in which the first array will contain all the even position elements and the second one will contain odd position elements.
  • The next step is to sort both the arrays so that we’ll get the second-largest elements from both the arrays.
  • At last, we’ve to add both the second-largest elements that we get from both the arrays.
  • Display the desired output in the main function.

Code Implementation:

#include <bits/stdc++.h>
using namespace std;
int smallLargeSum(int *arr, int n) {
    if(n <= 3) {
        return 0;
    }
    //Here we use vector because we don't know the array size, 
    //we can use array also but vector gives us more functionality than array
    vector<int> arrEven, arrOdd;
    //Break array into two different arrays even and odd
    for(int i = 0; i < n; i++) {
        //If Number is even then add it into even array
        if(i % 2 == 0) {
            arrEven.push_back(arr[i]);
        }
        else {
            arrOdd.push_back(arr[i]);
        }
    }
    //Sort the even array
    sort(arrEven.begin(), arrEven.end());
    //We use sort function from C++ STL library
    //Sort the odd array
    sort(arrOdd.begin(), arrOdd.end());
    //Taking second largest element from both arrays and add them
    return arrEven[1] + arrOdd[1];
}
// Driver code
int main()
{
    int n;
    cout<<"Enter How many elements you want to enter?\n";
    cin>>n;
    int arr[n];
    //Get input from user
    cout<<"Start entering the numbers\n";
    for(int i = 0; i < n; i++) {
        cin>>arr[i];
    }
    cout<<"Output is\n";
    cout<<smallLargeSum(arr, n);
    return 0;
}

Problem Statement 2

Write a function CheckPassword(str) which will accept the string as an argument or parameter and validates the password. It will return 1 if the conditions are satisfied else it’ll return 0?
The password is valid if it satisfies the below conditions:
a. It should contain at least 4 characters.
b. At least 1 numeric digit should be present.
c. At least 1 Capital letter should be there.
d. Passwords should not contain space or slash(/).
e. The starting character should not be a number.

Sample Test Case:
Input:
bB1_89

Output:
1

Approach:

  1. Using if condition check whether the length of string is greater than equal to 4 or not.
  2. Run a loop on the string and check if any character is a digit or not. It is a digit if it’s between ‘0’ and ‘9’.
  3. Iterate the string and check that only at least one letter should be between ‘A’ and ‘Z’, i.e it should be capital.
  4. Run a loop on string and check no character should match space(‘ ‘) or slash (‘/’).
  5. Check that the first character should not lie between ‘0’ and ‘9’.

Code Implementation

#include<iostream>
#include<string.h>
using namespace std;
int CheckPassword(char str[]) {
        int len = strlen(str);
        bool isDigit = false, isCap = false, isSlashSpace=false,isNumStart=false;
        //RULE 1: At least 4 characters in it
        if (len < 4)
            return 0;
        for(int i=0; i<len; i++) {
            //RULE 2: At least one numeric digit in it
            if(str[i]>='0' && str[i]<='9') {
        isDigit = true;
            }
            //RULE 3: At least one Capital letter 
            else if(str[i]>='A'&&str[i]<='Z'){
        isCap=true;
            }
            //RULE 4: Must not have space or slash
            if(str[i]==' '|| str[i]=='/')
        isSlashSpace=true;
        }
        //RULE 5: Starting character must not be a number
        isNumStart = (str[0]>='0' && str[0]<='9');
        //FYI: In C++, if int data type function returns the true then it prints 1 and if false then it prints 0
        return isDigit && isCap && !isSlashSpace && !isNumStart;
    }
int main() {
        char password[100];
        cout<<"Enter the Password\n";
        cin>>password;
        cout<<"The output is =\n";
        cout<<CheckPassword(password);
}

Problem Statement 3

A person’s body mass index is a simple calculation based on height and weight that classifies the person as underweight, overweight, or normal. The formula for metric unit is,

BMI = weight in kilograms / (height in meters)2

You are given a function,

Int GetBMICategory(int weight, float height);

The function accepts the weight (an integer number) and height (a floating point number) of a person as its arguments. Implement the function such that it calculations the BMI of the person and returns an integer, the person’s BMI category as per the given rules:

  1. If BMI < 18, return 0.
  2. If 18 >= BMI < 25, return 1.
  3. If 25 >= BMI <30, return 2.
  4. If 30 >= BMI < 40, return 3.
  5. If BMI >= 40, return 4.

Note:

  • Weight > 0 and its unit is kilogram.
  • Height > 0 and its unit is metre.
  • Compute BMI as a floating-point.

Sample Test Case:
Input:
42
1.54

Output:
0

Explanation:

The person’s weight is 42Kg and height is 1.54 metres BMI = weight in kilograms / (height in meters)2 = 42/(1.54 * 1.54) = 17.70

Since, BMI < 18, as per given rules, the output is 0.

Sample Input:

62
1.52

Sample Output:

2

Code Implementation

// BMI Problem statement

#include<iostream>

using namespace std;

int bmi(int weight, float height){

    float ans=weight/(height*height);

    if(ans<18)
         return 0;
    else if(ans>=18 && ans<25)
         return 1;
    else if(ans>=25 && ans<30)
         return 2;
    else if(ans>=30 && ans<40)
         return 3;
    else
         return 4;

}

int main(){   

    int weight;
    float height;
    cin>>weight>>height;
    cout<<bmi(weight,height);

}

related posts

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.