DeloitteIT Codes Zone

Deloitte Previous Coding Questions

πŸ”₯ Deloitte Coding Questions with Java & Python Solutions

Welcome to our coding practice series based on real Deloitte interview questions. In this post, we’ve compiled 4 commonly asked problems that test your grasp of strings, permutations, recursion, and text handling. For each problem, we’ve included:

  • A clear problem statement
  • Working Java and Python solutions
  • A detailed explanation

Let’s dive into the problems and improve your problem-solving skills! πŸ’ͺ

βœ… Problem 1: Unique Substrings / Permutation Count

πŸ“ Problem Statement: Unique Permutation Generator

You’re building a password generator system. Given a string, generate all unique permutations of that string.
The input string may contain repeated characters. Your output should contain no duplicates and should be sorted in lexicographical order.

πŸ”’ Input:

A string s (may contain repeated characters)
Example Input:
aba

🧾 Output:

All unique permutations printed line-by-line in lexicographical order.
Example Output:
aab
aba
baa

πŸ”£Code

πŸ” Explanation:

We generate all possible permutations and eliminate duplicates using a set.

  • In Java, TreeSet keeps elements sorted and unique.
  • In Python, set ensures uniqueness and sorted() gives the desired order.

This approach works well even when characters repeat.

βœ… Problem 2: String Rotation Check

πŸ“ Problem Statement: Rotation Validator

Check whether one string is a rotation of another.
A rotation means taking characters from the start of a string and moving them to the end without changing their order.

πŸ”’ Input:

Two strings s1 and s2
Example Input:
abcde
deabc

🧾 Output:

Example Output:
Yes

Return “Yes” if the second string is a valid rotation of the first, else “No”.

πŸ”£Code

πŸ” Explanation:

We double the first string and check if the second is a substring.
This technique is effective for rotation validation because:

  • All possible rotations of a string are present in its concatenation with itself.

βœ… Problem 3: Sum of Digits Until Single Digit

πŸ“ Problem Statement: Digital Root Calculation

You’re given a number. Your task is to repeatedly sum its digits until a single-digit result is obtained.

πŸ”’ Input:

A single integer num
Example Input:
987

🧾 Output:

A single-digit number
Example Output:
6
(Since 9 + 8 + 7 = 24 β†’ 2 + 4 = 6)

πŸ”£Code

πŸ” Explanation:

This process is often called the digital root.
The idea is to:

  • Convert the number to digits
  • Sum them
  • Repeat until a single digit remains

Efficient and simple to implement in both languages.

βœ… Problem 4: Special Character Removal & Word Count

πŸ“ Problem Statement: Clean Text and Count Words

You’re given a messy sentence full of symbols. Remove all non-alphabetic characters (except space) and count the number of words.

πŸ”’ Input:

A string of messy text
Example Input:
Hello! This is #100% amazing.

🧾 Output:

An integer indicating the number of valid words
Example Output:
5

πŸ”£Code

πŸ” Explanation:

We clean the text (using loop in Python and regex in Java):

Remove everything except alphabets and spaces

Split the cleaned sentence into words

Count them

This is useful in text preprocessing and word analysis tasks.

🚨 Deloitte Overview!


Want to know how Deloitte’s exam process works, what rounds to expect, and other important details? Check out this complete overview:
🌐 https://nextgenkodinghub.in/deloitte-overview/

All the best! πŸ’Ό


Thanks for visiting! Explore the categories below for more exciting and useful content.


 

Leave a Reply

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