ACCENTURE INTERVIEW CODING QUESTION 2024 | 20th AUGUST
ACCENTURE INTERVIEW CODING QUESTION 2024 | 20th AUGUST

ACCENTURE INTERVIEW CODING QUESTION 2024 | 20th AUG

ACCENTURE INTERVIEW CODING QUESTION 2024 | 20th 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 20th.

ACCENTURE INTERVIEW CODING QUESTION 2024 | 20th AUG
Q1. The String Decoder: You are provided with a string which has a sequence of 1s and 0s. This sequence is the encoded version of a english word. You are supposed to write a program to decode the provided string and find the original word. Each Alphabet is representing by a sequence of 1s.

A:1
B:11
C: 111
D: 1111
E: 11111
And so on upto Z having 26 1s

The sequence of 1s in the encoded form are separated by single 0 which helps to distinguish between 2 letters.

Note: Input String will always be in uppercase
Example 1: 101101110
Ans: ABC

Example 2: 11101111011111
Ans: CDE
def decode_string(encoded_string):
    decoded_word = ""
    current_count = 0

    for char in encoded_string:
        if char == '1':
            current_count += 1
        elif char == '0':
            decoded_word += chr(64 + current_count)
            current_count = 0
    
    # Add the last character if there is no trailing 0
    if current_count > 0:
        decoded_word += chr(64 + current_count)

    return decoded_word

print(decode_string("101101110"))  # Output: ABC
print(decode_string("11101111011111"))  # Output: CDE
public class StringDecoder {
    public static String decodeString(String encodedString) {
        StringBuilder decodedWord = new StringBuilder();
        int currentCount = 0;

        for (char c : encodedString.toCharArray()) {
            if (c == '1') {
                currentCount++;
            } else if (c == '0') {
                decodedWord.append((char)(64 + currentCount));
                currentCount = 0;
            }
        }

        // Add the last character if there is no trailing 0
        if (currentCount > 0) {
            decodedWord.append((char)(64 + currentCount));
        }

        return decodedWord.toString();
    }

    public static void main(String[] args) {
        System.out.println(decodeString("101101110")); // Output: ABC
        System.out.println(decodeString("11101111011111")); // Output: CDE
    }
}
#include <iostream>
#include <string>

using namespace std;

string decodeString(const string &encodedString) {
    string decodedWord = "";
    int currentCount = 0;

    for (char c : encodedString) {
        if (c == '1') {
            currentCount++;
        } else if (c == '0') {
            decodedWord += char(64 + currentCount);
            currentCount = 0;
        }
    }

    // Add the last character if there is no trailing 0
    if (currentCount > 0) {
        decodedWord += char(64 + currentCount);
    }

    return decodedWord;
}

int main() {
    cout << decodeString("101101110") << endl;  // Output: ABC
    cout << decodeString("11101111011111") << endl;  // Output: CDE

    return 0;
}
function decodeString(encodedString) {
    let decodedWord = "";
    let currentCount = 0;

    for (let i = 0; i < encodedString.length; i++) {
        if (encodedString[i] === '1') {
            currentCount++;
        } else if (encodedString[i] === '0') {
            decodedWord += String.fromCharCode(64 + currentCount);
            currentCount = 0;
        }
    }
    
    // Add the last character if there is no trailing 0
    if (currentCount > 0) {
        decodedWord += String.fromCharCode(64 + currentCount);
    }

    return decodedWord;
}

console.log(decodeString("101101110")); // Output: ABC
console.log(decodeString("11101111011111")); // Output: CDE

Explaination with key points

ACCENTURE INTERVIEW CODING QUESTION 2024 | 16th AUG

Step-by-Step Explanation:

  1. Initialization:
    • Start by initializing 2 variables:
      • decodedWord: A variable (string) to store the decoded word as you process the encoded string.
      • currentCount: It’s an integer variable to keep track of the count of consecutive 1s.
  2. Iterating through the Encoded String:
    • Loop through each character in the encoded string through Forloop.
    • If the character is equal to '1':
      • The currentCount is incremented by 1. This count represents the position of the letter in the alphabet (e.g., 1 means A, 2 means B,…so on).
    • If the character is equal to '0':
      • Convert the currentCount to the corresponding alphabet character using ASCII values.
        • Add 64 to currentCount because the ASCII value of 'A' is 65, & 1 should correspond to A.
      • Append the resulting character to decodedWord.
      • Reset currentCount to 0, ready to start counting the next sequence of 1s.
  3. Handling the Last Character:
    • After the loop, check if there is a non-zero currentCount left.
    • If so, convert currentCount to the corresponding character and append it to decodedWord.
  4. Return the Decoded Word:
    • Finally, return or print the decodedWord value, which now contains the fully decoded message.
Q2. A googly prime number is defined as a number that is derived from the sum of its individual digits. For example, if N = 43, the sum of its individual digits is 4+3 = 7, which is prime making it a googly prime number.

Your task is to find whether the current number is googly prime number or not.

Input: 43

Output: Yes
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

def is_googly_prime(number):
    sum_of_digits = sum(int(digit) for digit in str(number))
    return "Yes" if is_prime(sum_of_digits) else "No"

print(is_googly_prime(43))  # Output: Yes
print(is_googly_prime(20))  # Output: No
public class GooglyPrime {
   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 String isGooglyPrime(int number) {
    int sumOfDigits = 0;
    int num = number;

    while (num > 0) {
        sumOfDigits += num % 10;
        num /= 10;
    }

    return isPrime(sumOfDigits) ? "Yes" : "No";
}

public static void main(String[] args) {
    System.out.println(isGooglyPrime(43)); // Output: Yes
    System.out.println(isGooglyPrime(20)); // Output: No
}
}
#include <iostream>
#include <cmath>

using namespace std;

bool isPrime(int n) {
    if (n <= 1) return false;
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) return false;
    }
    return true;
}

string isGooglyPrime(int number) {
    int sumOfDigits = 0;
    int num = number;

    while (num > 0) {
        sumOfDigits += num % 10;
        num /= 10;
    }

    return isPrime(sumOfDigits) ? "Yes" : "No";
}

int main() {
    cout << isGooglyPrime(43) << endl;  // Output: Yes
    cout << isGooglyPrime(20) << endl;  // Output: No

    return 0;
}
function isPrime(n) {
       if (n <= 1) return false;
       for (let i = 2; i <= Math.sqrt(n); i++) {
             if (n % i === 0) return false;
       }
       return true;
}
function isGooglyPrime(number) {
       let sumOfDigits = 0;
       let num = number;

       while (num > 0) {
             sumOfDigits += num % 10;
             num = Math.floor(num / 10);
       }

      return isPrime(sumOfDigits) ? "Yes" : "No";
}

console.log(isGooglyPrime(43)); // Output: Yes
console.log(isGooglyPrime(20)); // Output: No

Step-by-Step Explanation:

Extract the Digits:

  • Just begin with the given number (e.g., 43).
  • Extract each digit by taking the modulus with 10 (e.g., 43 % 10 gives 3).
  • Add the digit to sumOfDigits.
  • Update the no. by removing the last digit (e.g., 43 / 10 gives 4).

Sum the Digits:

  • Continue extracting and summing the digits until the number becomes 0.
  • For example, for value 43, sum the digits 4 + 3 to get 7.

Check Prime:

  • Check if the sum obtained (e.g., 7) is a prime number:
    • Prime numbers are those > 1 that are only divisible by 1 and themselves.
    • Iterate from 2 to the square root of the sum to check for factors.
    • If any factor divides the sum, it’s not prime; otherwise, it is prime.

Return the Result:

  • If the sum is prime, return “Yes.”
  • Otherwise, return “No.”

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 *