Deloitte Coding Sheet
Deloitte Coding Sheet
Problem Statement:
In a distant kingdom, a wise king has a chest full of magical numbers. He decides to reward the
most observant mathematician in the land. Your task is to analyze a list of these numbers and
identify which ones contain an even number of digits. The king believes that only numbers with
an even number of digits hold the key to unlock the hidden treasures of the kingdom. Can you
help identify these numbers for the king?
Constraints:
Sample Input:
123,4567,89,1001,22
Sample Output:
4567, 89, 1001, 22
Explanation:
Numbers like 123 have 3 digits, which is odd, so they are excluded. However, 89 and 22 have 2
digits, which is even, so they are included.
2. Making Anagrams
Problem Statement:
Alice is attending a cryptography class and has discovered that anagrams can be very useful.
She is working on an encryption scheme that involves two large strings. The encryption is
dependent on determining the minimum number of character deletions required to turn the
two strings into anagrams.
Two strings are considered anagrams if the letters of one string can be rearranged to form the
other string, meaning both strings must contain the same exact letters in the same exact
frequencies.
Given two strings, your task is to calculate the minimum number of deletions required to make
them anagrams. Characters can be deleted from either string.
Constraints:
Input Format:
Output Format:
● Print a single integer denoting the minimum number of character deletions required to
make the strings anagrams.
Sample Input:
cde
abc
Sample Output:
Explanation:
To make the strings anagrams:
Problem Statement:
A mysterious letter arrives at your doorstep containing a cryptic message. The letter reads:
"Decode the message to reveal the treasure." The message is encoded using nested repetition,
such as "2[a3[b]]", where numbers indicate the number of repetitions. Your task is to decode
such messages. For instance, "2[a3[b]]" expands to "abbbabbb". Can you solve this puzzle and
unveil the treasure?
Constraints:
● The encoded string contains only alphanumeric characters, square brackets, and digits.
● The maximum nesting level is 100.
● The length of the encoded string does not exceed 10^4.
Sample Input:
"3[a2[bc]]"
Sample Output:
"abcbcabcbcabcbc"
Explanation:
The innermost part "2[bc]" expands to "bcbc". Then, "3[a2[bc]]" expands to "abcbcabcbcabcbc".
Problem Statement:
A famous mathematician has been studying binary sequences and discovered a fascinating
pattern. He realized that there are certain substrings where the number of 0s is equal to the
number of 1s. Intrigued by this observation, he asks you to help find how many such substrings
exist in a given binary string. The mathematician believes that these balanced substrings can
lead to new discoveries in the world of numbers. Can you find them?
Constraints:
Sample Input:
"00110011"
Sample Output:
6
Explanation:
The six balanced substrings are: "0011", "01", "1100", "10", "0011", and "01".
Problem Statement:
In a grand military parade, soldiers march in a straight line. Some soldiers are facing left, while
others are facing right. Every time a soldier facing right comes across a soldier facing left, they
exchange a salute. Your task is to calculate how many salutes happen in total. Can you
determine the total number of salutes based on the arrangement of soldiers in the parade?
Constraints:
Sample Input:
"><<<>"
Sample Output:
2
Explanation:
There are two salutes: one between the first '>' and the first '<', and the second between the
third '>' and the third '<'.
Problem Statement:
A peculiar list of words has been found, where each word contains an embedded number
indicating its position in the correct order. Your task is to rearrange the words in the correct order
based on these embedded numbers. For example, "is2" and "Th1is" should be placed in the
correct sequence based on their numbers. Can you sort the list and reveal the correct sequence
of words?
Constraints:
Sample Output:
This is a
Explanation:
The word "This" contains 1, so it comes first, followed by "is" and then "a".
Problem Statement:
In a grand palace, the floor is decorated with concentric squares made of numbers. The
outermost square has the largest number, and each subsequent inner square has a smaller
number. Your task is to construct these concentric squares based on a given size n. The size of
each square decreases as you move towards the center. Can you create the beautiful design of
concentric squares for the palace?
Constraints:
Sample Input:
3
Sample Output:
Explanation:
The outer square has the number 3, the next one has 2, and the innermost square has 1.
Constraints:
Sample Input:
["hello3", "world2"]
Sample Output:
"hellohellohello worldworld"
Explanation:
"hello3" repeats "hello" 3 times, and "world2" repeats "world" 2 times.
Problem Statement:
In a small village, people celebrate their happiness by performing a ritual with numbers. A
number is considered "happy" if the process of repeatedly summing the squares of its digits
eventually leads to 1. For example, the number 19 is happy because 1^2+ 9^2 = 82, 8^2 + 2^2=
68, and so on, eventually reaching 1. Your task is to find all happy numbers in a given range.
Can you help the villagers find their happy numbers?
Constraints:
Sample Input:
1, 20
Sample Output:
[1, 7, 10, 13, 19]
Explanation:
The happy numbers between 1 and 20 are 1, 7, 10, 13, and 19.
10. Evaluate Product of Array Excluding the Current Index
Problem Statement:
In a world where magical creatures live in harmony, every creature has a unique power level
represented by an array. However, to determine the total power, each creature wants to know
the total power of all others except itself. Can you calculate the product of all numbers in the
array except the current one for each index, without using division? The creatures will be very
grateful if you can solve this for them.
Constraints:
Sample Input:
[1, 2, 3, 4]
Sample Output:
[24, 12, 8, 6]
Explanation:
For the first index, the product of all other numbers is 2×3×4=242 \times 3 \times 4 = 24.
Similarly, for the second index, it's 1×3×4=121 \times 3 \times 4 = 12, and so on.
Problem Statement:
A skilled artist is designing a pyramid-like pattern using numbers for a grand festival. The
pyramid consists of numbers arranged in increasing order from the top to the base, forming
rows. Each row in the pyramid contains a sequence of numbers that increases from 1 up to the
row number. The artist needs your help to create this pyramid pattern for any given number of
rows. Can you design the pyramid pattern for the festival?
Constraints:
Sample Input:
4
Sample Output:
1
1 2
1 2 3
1 2 3 4
Explanation:
For 4 rows, the pyramid starts with "1" at the top, then "1 2" on the next row, and so on,
increasing the number sequence with each row.
Problem Statement:
Two friends, Alice and Bob, were given two strings and challenged to check if one is a
permutation of the other. Alice insists that a permutation should contain the same characters but
in a different order. Bob, on the other hand, is skeptical. Can you help them by determining if
one string is a permutation of the other?
Constraints:
Sample Input:
"abc", "cab"
Sample Output:
True
Explanation:
Both strings contain the same characters in different orders, so they are permutations of each
other.
Problem Statement:
In a world of balanced equations, mathematicians have designed a set of parentheses rules.
Each pair of balanced parentheses has a score based on its depth, where deeper pairs have
higher scores. Your task is to calculate the total score of the balanced parentheses string, where
each pair of parentheses has a score equal to the sum of its score at that depth. Can you help
them evaluate the score of the parentheses?
Constraints:
Sample Input:
"(()())"
Sample Output:
6
Explanation:
The score of the string is calculated as follows: the outermost pair contributes 2, and the inner
pair contributes 4, making the total score 6.
Problem Statement:
At a royal banquet, there are a number of seats arranged in a circular fashion. The guests must
be seated such that there is a specific gap between each of them. Your task is to arrange the
guests in these seats while maintaining the required gaps. Can you solve the seating
arrangement puzzle?
Constraints:
Sample Input:
4, 2
Sample Output:
[1, 3, 4, 2]
Explanation:
The guests are seated in positions 1, 3, 4, and 2 to maintain a gap of 2 between each guest.
Constraints:
Sample Input:
"abca"
Sample Output:
"abba"
Explanation:
The smallest palindrome that can be formed is "abba".
Problem Statement:
A wizard has encoded a series of operations into a nested list format, and you must decode it to
evaluate the result. Each operation may involve simple arithmetic or deeper nested operations.
Your task is to evaluate the expression after decoding the nested list. Can you help the wizard
solve the encoded equation?
Constraints:
Sample Input:
["1", "+", ["2", "*", "3"]]
Sample Output:
7
Explanation:
The decoded operation is 1+(2∗3)=7
17. Calculate the Number of Subsequences in an Array that Meet a
Condition
Problem Statement:
In a kingdom of arrays, there is a rule that only certain subsequences can be accepted for the
royal collection. Your task is to calculate how many subsequences in a given array meet a
specific condition. The condition involves checking if the subsequence satisfies certain
arithmetic properties. Can you calculate the number of such subsequences?
Constraints:
Sample Input:
[1, 2, 3]
Sample Output:
6
Explanation:
There are 6 subsequences: [1], [2], [3], [1, 2], [1, 3], [2, 3].
Problem Statement:
In a library of books, you are tasked with identifying the first occurrence of one word within
another. The librarian has given you two words, and you must determine where the second
word first appears in the first word. Can you find the position of the first occurrence efficiently?
Constraints:
Sample Input:
"hello", "ll"
Sample Output:
2
Explanation:
The word "ll" first appears at index 2 in "hello".
19. Calculate the Total XOR of All Subsets of an Array
Problem Statement:
A group of mathematicians has been studying the properties of the XOR operation, and they are
particularly interested in the XOR of all possible subsets of an array. Your task is to calculate the
total XOR of all subsets. Can you help them with this complex mathematical task?
Constraints:
Sample Input:
[1, 2, 3]
Sample Output:
0
Explanation:
The total XOR of all subsets is 0.
Problem Statement:
In a kingdom of sums, there is a challenge where you must find all subarrays whose sum equals
a given value. The kingdom's ruler has given you an array, and you must determine how many
subarrays meet this condition. Can you solve the sum puzzle?
Constraints:
Sample Input:
[1, 2, 3], 3
Sample Output:
2
Explanation:
There are 2 subarrays that sum up to 3: [1, 2] and [3].
21. Find Numbers in an Array with an Even Number of Digits
Problem Statement:
A mathematician in the kingdom is fascinated by the number of digits in numbers. He wonders
how many numbers in an array have an even number of digits. Your task is to find how many
numbers in the given array have an even number of digits. Can you solve the puzzle?
Constraints:
Sample Input:
[12, 345, 2, 6, 7896]
Sample Output:
2
Explanation:
The numbers 12 and 7896 have an even number of digits.
Problem Statement:
A kingdom has many different types of spells, represented as words. Each spell can be cast in
multiple ways, with the same letters rearranged. Your task is to group the spells (strings) that
are anagrams of each other. Can you group the anagrams and display them together?
Constraints:
Sample Input:
["eat", "tea", "tan", "ate", "nat", "bat"]
Sample Output:
[["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]
Explanation:
"eat", "tea", and "ate" are anagrams of each other, and "tan" and "nat" are another group.
Input:
Output:
● A list of integers, where each integer indicates the number of sticks remaining before
each cut.
Example
Input:
n = 6
arr = [5, 4, 4, 2, 2, 8]
Output:
[6, 4, 2, 1]
Explanation:
Alice and Bob each created a challenge. These challenges are scored based on three
categories: clarity, originality, and difficulty. The scores for Alice's challenge are given as a =
[a[0], a[1], a[2]], and the scores for Bob's challenge are given as b = [b[0], b[1],
b[2]].
Task:
You need to calculate the total points for Alice and Bob and return them as [Alice's score,
Bob's score].
Input:
Output:
Example:
Input:
1. a = [5, 6, 7]
2. b = [3, 6, 10]
Output:
[1, 1]
Explanation:
Constraints:
Problem Statement:
In a kingdom of words, the royal scholars have tasked you with finding the longest palindromic
substring from a given string. A palindrome is a string that reads the same forwards and
backwards. The scholars want to know which substring in the string is the longest palindrome.
Can you help them solve this problem?
Constraints:
Sample Input:
"babad"
Sample Output:
"bab" (or "aba")
Explanation:
The longest palindromic substring is "bab" or "aba". Both are valid answers.
A teacher asks the class to turn to a specific page number in a book. A student can start turning
pages either from the front of the book or the back. The task is to calculate the minimum
number of page turns required to reach the desired page.
Rules:
Examples:
Example 1:
Input:
n = 6
p = 2
Output:
Explanation:
Example 2:
Input:
n = 5
p = 4
Output:
Explanation:
Problem Statement:
In a busy railway station, trains are scheduled to arrive and depart at specific times. You need to
determine the minimum number of platforms required to accommodate all the trains at the
station at any given time. Can you calculate this efficiently?
Constraints:
Sample Input:
Arrivals: [100, 101, 300], Departures: [200, 400, 500]
Sample Output:
2
Explanation:
At time 100, the first train arrives. At time 200, the first train departs, and the second train
arrives. The station needs 2 platforms at the peak time.
Problem Statement:
A mathematician in the kingdom is studying the divisors of numbers. He wants to find all divisors
of a given number efficiently. Your task is to compute and return all divisors of a number. Can
you help him with this problem?
Constraints:
Sample Input:
28
Sample Output:
[1, 2, 4, 7, 14, 28]
Explanation:
The divisors of 28 are 1, 2, 4, 7, 14, and 28.
Julius Caesar encrypted his messages using a cipher that shifts each letter of the alphabet by a
fixed number of positions. If the shift moves past the end of the alphabet, it wraps around to the
beginning.
Problem Description:
Given a string s, encrypt it using a Caesar cipher with a shift value k. Non-alphabetic characters
(such as -) remain unchanged.
Rules:
Constraints:
● 1≤length of s≤100
● 0≤k≤1000
Example Input/Output:
Input:
11
middle-Outz
Output:
okffng-Qwvb
Explanation:
Problem Statement:
In a kingdom, there is a magical 2D matrix where each row is sorted in ascending order from left
to right, and the first element of each row is greater than the last element of the previous row.
Your task is to search for a target number in the matrix. Can you find it efficiently?
Constraints:
Sample Input:
Matrix:
[
[1, 4, 7, 11],
[2, 5, 8, 12],
[3, 6, 9, 16],
[10, 13, 14, 17]
]
Target: 5
Sample Output:
True
Explanation:
The target number 5 exists in the matrix at position (1, 1), so the result is True.
Prime coders,
If you are done try to solve codechef <1000 rating questions. (Happy Coding)