ACCENTURE CODING QUESTION INTERVIEW 2024 | CODING ROUND

ACCENTURE INTERVIEW CODING QUESTION 2024 | 16th AUG

ACCENTURE INTERVIEW CODING QUESTION 2024 | 16th AUGUST

ACCENTURE INTERVIEW CODING QUESTION 2024. Preparing for Accenture’s 2024 coding interviews? Here’s what you should know! In this piece, we’ll go over the some types of coding questions you can encounter during your upcoming Accenture interview, Whether you’re aiming for a software engineering IT role or a tech-related position, these question will assist you to crack Accenture Coding Round Interviews. Below some Accenture Interview coding question 2024 appeared on Aug 16th.

ACCENTURE INTERVIEW CODING QUESTION 2024 | 16th AUG

Prob 1. Jack has an array A of length N. He wants to label whether the number in the array is even or odd. Your task is to help him find & return a string with labels even or odd in sequence according to which the numbers appear in the array.

Accenture Official Platform

Explaination with key points

  1. Initialize a Collection to Store Labels: Simply Create an empty list, array, or string builder to hold the labels (“even” / “odd”) corresponding to each number in the array.
  2. Iterate Through the Array: Loop through each element in the array A using an appropriate loop (e.g., for loop). Access the current number in the array during every iteration,
  3. Determine If the Number is Even/Odd: For each number, check whether it is even or odd: A number is even if divisible by 2 without a remainder (number % 2 == 0) if the number is odd if it is not divisible by 2 (number % 2 != 0).
  4. Store the Final Label: Based on the result of the even or odd check, append or add the label “even” or “odd” to the collection already initialized in step one.
  5. Join the Labels into a String: After processing all elements, join the labels into a string with spaces separating each label. This will create a string that describes the sequence of “even” and “odd” labels corresponding to the numbers.
  6. Return the Resultant String: Return the final string that contains the sequence of “even” as well as “odd” labels.

def label_even_odd(A):
labels = []
for number in A:
if number % 2 == 0:
labels.append(“even”)
else:
labels.append(“odd”)
return ‘ ‘.join(labels)

A = [1, 2, 3, 4, 5]
result = label_even_odd(A)
print(result) # Output: “odd even odd even odd”

public class EvenOddLabeler {
public static String labelEvenOdd(int[] A) {
StringBuilder labels = new StringBuilder();
for (int number : A) {
if (number % 2 == 0) {
labels.append(“even”);
} else {
labels.append(“odd”);
}
labels.append(” “); // Add space after each label }
return labels.toString().trim(); // Remove the last trailing space
}


public static void main(String[] args) {
int[] A = {1, 2, 3, 4, 5};
String result = labelEvenOdd(A);
System.out.println(result); // Output: “odd even odd even odd”
}
}

#include <iostream>
#include <vector>
#include <string>
#include <sstream>

std::string labelEvenOdd(const std::vector& A) {
std::ostringstream labels;
for (int number : A) {
if (number % 2 == 0) {
labels << “even “;
} else {
labels << “odd “;
}
}
std::string result = labels.str();
result.pop_back(); // Remove the trailing space
return result;
}

int main() {
std::vector A = {1, 2, 3, 4, 5};
std::string result = labelEvenOdd(A);
std::cout << result << std::endl; // Output: “odd even odd even odd”
return 0;
}

function labelEvenOdd(A) {
let labels = [];
for (let number of A) {
if (number % 2 === 0) {
labels.push(“even”);
} else {
labels.push(“odd”);
}
}
return labels.join(” “);
}

// Example usage:
let A = [1, 2, 3, 4, 5];
let result = labelEvenOdd(A);
console.log(result); // Output: “odd even odd even odd”

HOW TO USE GROK 2.0 AI IMAGE GENERATOR

You are given a string S and your task is to find and return the count of permutation formed by fixing the positions of the vowels present in the string.

Note: 1. The result is non-negative
2. If there are no consonants then return 0.

def factorial(n):
if n == 0:
return 1
return n * factorial(n – 1)

def permutation_count_without_vowels(string):
vowels = set(‘aeiouAEIOU’)
count = sum(1 for char in string if char not in vowels)
return factorial(count)

str = “abcdds”
result = permutation_count_without_vowels(str)
print(result) # Output: 120

import java.util.HashSet;
import java.util.Set;

public class PermutationWithoutVowels {
public static int factorial(int n) {
if (n == 0) {
return 1;
}
return n * factorial(n – 1);
}

public static int permutationCountWithoutVowels(String str) {
Set<Character> vowels = new HashSet<>();

vowels.add(‘a’); vowels.add(‘e’); vowels.add(‘i’);
vowels.add(‘o’); vowels.add(‘u’);

vowels.add(‘A’); vowels.add(‘E’); vowels.add(‘I’)
vowels.add(‘O’); vowels.add(‘U’);

int count = 0;
for (char ch : str.toCharArray()) {
if (!vowels.contains(ch)) {
count++;
}
}


return factorial(count);
}


public static void main(String[] args) {
String str = “abcdds”;
int result = permutationCountWithoutVowels(str);
System.out.println(result); // Output will be 120
}

}

#include <iostream>
#include <set>

int factorial(int n) {
if (n == 0) {
return 1;
}
return n * factorial(n – 1);
}

int permutationCountWithoutVowels(const std::string& str) {
std::set vowels = {‘a’, ‘e’, ‘i’, ‘o’, ‘u’, ‘A’, ‘E’, ‘I’, ‘O’, ‘U’};
int count = 0;
for (char ch : str) {
if (vowels.find(ch) == vowels.end()) {
count++;
}
}


return factorial(count);
}

int main() {
std::string str = “abcdds”;
int result = permutationCountWithoutVowels(str);
std::cout << result << std::endl; // Output will be 120
return 0;
}

function factorial(n) {
if (n === 0) {
return 1;
}
return n * factorial(n – 1);
}

function permutationCountWithoutVowels(str) {
const vowels = new Set([‘a’, ‘e’, ‘i’, ‘o’, ‘u’, ‘A’, ‘E’, ‘I’, ‘O’, ‘U’]);

let count = 0;
for (let char of str) {
if (!vowels.has(char)) {
count++;
}
}

return factorial(count);
}

// Example usage:
let str = “abcdds”;
let result = permutationCountWithoutVowels(str);
console.log(result); // Output: 120

Explaination with key points

  1. Define a Funct for Calculating Factorial(!):
    • Implement a recursive/iterative function to find the factorial of a given number n. The factorial of n is the product/multiplication of all positive integers =< n.
  2. Create a Set of Vowels:
    • Define a set containing all the vowels (both uppercase & lowercase) to quickly identify. And filter out vowels from the passed string.
    • The set should include all the vowel characters(in Capital or Non-Capital letter): ‘a’, ‘e’, ‘i’, ‘o’, ‘u’, ‘A’, ‘E’, ‘I’, ‘O’, ‘U’.
  3. Count the Consonants in the Str:
    • Initialize a counter to 0.
    • Iterate through each character in the string:
      • If the character is not in the vowel set (i.e., it is a consonant), increment the counter by 1(++).
  4. Calculate the Permutations:
    • Once the number of consonants has been determined, calculate the no. of permutations by taking the factorial(!) of this count.
    • This step assumes that all consonants are distinct, & hence the no. of permutations is counted! (factorial of the count).
  5. Return the Result:
    • Return the result from the factorial calculation, which represents the total no. of distinct permutations that can be created using only the consonants in the str.

Basic Example

For a string “abcdds”, follow these steps below:

  • The consonants are b, c, d, d, s.
  • There are 5 consonants, so the number of permutations is 5! = 120.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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