0% found this document useful (0 votes)
2 views

SET 1

The document outlines several programming challenges, including finding substrings in a string and its reverse, calculating the percentage of a specific letter in a string, determining the sender with the largest word count from chat logs, and validating a PAN number format. Each challenge includes constraints and test cases to illustrate the expected functionality. The document serves as a guideline for developing algorithms to solve these problems.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SET 1

The document outlines several programming challenges, including finding substrings in a string and its reverse, calculating the percentage of a specific letter in a string, determining the sender with the largest word count from chat logs, and validating a PAN number format. Each challenge includes constraints and test cases to illustrate the expected functionality. The document serves as a guideline for developing algorithms to solve these problems.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

Existence of a Substring in a String and Its Reverse

Given a string s, find any Substring of length 2 which is also present in the reverse of s.
Return true if such a substring exists, and false otherwise.
Constraints:
· 1 <= s.length <= 100
· s consists only of lowercase English letters.

Test Case 1:
Input: s = “abcd”
Output: false
Explanation: There is no substring of length 2 in s, which is also present in the reverse
of s.

Test Case 2:
Input: s = “abcba”
Output: true
Explanation: All of the substrings of length 2 "ab", "bc", "cb", "ba" are also present in
reverse(s) == "abcba".

Test Case 3:
Input: s = “leetcode”
Output: true
Explanation: Substring "ee" is of length 2 which is also present in reverse(s) ==
"edocteel".
2.Percentage of Letter in String:

Given a string s and a character letter, return the percentage of characters in s that
equal letter rounded down to the nearest whole percent.
Constraints:
· 1 <= s.length <= 100
· s consists of lowercase English letters.
· letter is a lowercase English letter.

Test Case 1:
Input: s = “Bannari” , letter = “n”
Output : 28
Explanation:
The percentage of characters in s that equal the letter ‘n’ is 2/ 7* 100% = 28% when
rounded down, so we return 28.

Test Case 2:
Input: s = “jjjj”, letter = “k”
Output: 0
Explanation:
The percentage of characters in s that equal the letter 'k' is 0%, so we return 0.
3.Sender With Largest Word Count:

You have a chat log of n messages. You are given two string arrays messages and
senders where messages[i] is a message sent by senders[i].
A message is list of words that are separated by a single space with no leading or
trailing spaces. The word count of a sender is the total number of words sent by the
sender. Note that a sender may send more than one message.
Return the sender with the largest word count. If there is more than one sender with the
largest word count, return the one with the lexicographically largest name.
Note:
Uppercase letters come before lowercase letters in lexicographical order.
“Alice” and “alice” are distinct.

Constraints:
· n == messages.length == senders.length
· 1 <= n <= 104
· 1 <= messages[i].length <= 100
· 1 <= senders[i].length <= 10
· messages[i] consists of uppercase and lowercase English letters and ' '.
· All the words in messages[i] are separated by a single space.
· messages[i] does not have leading or trailing spaces.
· senders[i] consists of uppercase and lowercase English letters only.

Test Case 1:
Input:
messages = ["How is leetcode for everyone","Leetcode is useful for practice"],
senders = ["Bob","Charlie"]
Output: "Charlie"

Explanation:
Bob sends a total of 5 words.
Charlie sends a total of 5 words.
Since there is a tie for the largest word count, we return the sender with the
lexicographically larger name, Charlie.

Test Case 2:
messages = ["Hello userTwooo","Hi userThree","Wonderful day Alice","Nice day
userThree"],
senders = ["Alice","userTwo","userThree","Alice"]

Output: "Alice"
Explanation:
· Alice sends a total of 2 + 3 = 5 words.
· userTwo sends a total of 2 words.
· userThree sends a total of 3 words.
Since Alice has the largest word count, we return "Alice".
4.Longest Repeating Character Replacement:

You are given a string s and an integer k. You can choose any character of the string
and change it to any other uppercase English character. You can perform this operation
at most k times.
Return the length of the longest substring containing the same letter you can get after
performing the above operations.
Constraints:
· 1 <= s.length <= 105
· s consists of only uppercase English letters.
· 0 <= k <= s.length

Test Case 1:

Input: s = "AABABBA", k = 1
Output: 4
Explanation: Replace the one 'A' in the middle with 'B' and form "AABBBBA".
The substring "BBBB" has the longest repeating letters, which is 4.

Test Case 2:
Input: s = "ABAB", k = 2
Output: 4
Explanation: Replace the two 'A's with two 'B's or vice versa.

Test Case 3:
Input:
s = "AAABBBCCC"
k=2
Output:5
Explanation: Replace the two 'A's with 'B's the Output is 5
5. Decode String

Given an encoded string, return its decoded string. The encoding rule is: k[encoded_string],
where the encoded_string inside the square brackets is being repeated exactly k times. Note
that k is guaranteed to be a positive integer.

You may assume that the input string is always valid; there are no extra white spaces, square
brackets are well-formed, etc. Furthermore, you may assume that the original data does not
contain any digits and that digits are only for those repeat numbers, k.
For example, there will not be input like 3a or 2[4].

Constraints: 1 <= s.length <= 30


s consists of lowercase English letters, digits, and square brackets '[]'.
s is guaranteed to be a valid input.
All the integers in s are in the range [1, 300].

Test Case 1:
Input: s = "3[a]2[bc]"
Output: "aaabcbc"

Test Case 2:
Input: s = "3[a2[c]]"
Output: "accaccacc"

Test Case 3:
Input: s = "2[abc]3[cd]ef"
Output: "abcabccdcdcdef"
6.Anagram Checker

Anagram checker for an online word game. The game works as follows: players input a
word, and the program must determine whether the word can be formed using a set of
provided letter tiles. Players are allowed to use any subset of the given tiles to form their
word, and the tiles can be used multiple times. The game must provide an immediate
response as players submit their words.

Constraint: Maximum number of tiles provided: 7

Test Case 1:

Provided tiles: "a", "b", "c".


Player's word: "abc".

Output:
Valid anagram.

Test Case 2:

Provided Tiles: "a", "b", "c", "a"


Player's Word: "aabc"

Expected Output: True (the player's word can be formed using the provided tiles,
including duplicates)

Test Case 3:

Provided Tiles: "a", "b", "c"


Player's Word: "abcc"

Output: False (the player's word contains a letter 'c' which is not present in the provided
tiles)
7.Sorting String

Organize a list of book titles from a library catalog. The titles are stored in an array of
strings. Your objective is to develop a method to arrange the book titles in alphabetical
order.

Test Case 1;

Sample Input:
["apple", "banana", "cherry", "date"]

Sample Output:
["apple", "banana", "cherry", "date"]

Test Case 2:

Sample Input:
["zebra", "lion", "tiger", "elephant"]

Sample Output:
["elephant", "lion", "tiger", "zebra"]

Test Case 3:

Sample Input:
["cat", "fish", "dog", "elephant"]

Sample Output:
["cat", "dog", "elephant", "fish"]
8.Your task is to develop a program that validates PAN (Permanent Account Number)
according to the rules and format set by the Indian government. A valid PAN number in
India follows this format: "AAAAA9999A" where "A" represents an uppercase alphabet,
"9" represents a digit, and the last character is an uppercase alphabet. Furthermore, a
valid PAN card consists of exactly 10 characters.
PAN CARD RULES:
A PAN typically has the format of ABCTY1234D. The first three characters, denoted as
‘ABC’, represent an alphabetic series ranging between AAA and ZZZ. The 4th character
can include {A,B,C,F,G,H,L,J,P,T,F}} 'T', indicates the PAN holder’s status, with 'T' for
Trust, 'F' for Firm, 'H' for HUF, 'P' for Individual, 'C' for Company, etc. The 5th character,
'Y', signifies the first alphabet of the PAN holder’s last name. The subsequent four
characters are sequential digits ranging between 0001 and 9999. Finally, the 10th
character, 'D', serves as an alphabetic check digit running from A to Z.

Test Case 1:
Sample Input: "ABCDE1234A"

Expected Output: "Invalid PAN Number"


The PAN number "ABCDE1234A" does not conforms to the specified format

Test Case 2:

Sample Input: "ABCDE56789P"

Expected Output: "Invalid PAN Number"


The PAN number "ABCDE56789P" does not conform to the specified format

Test Case 3:

Sample Input : "PQRTS1234C"

Expected Output : "Valid PAN Number"


The PAN number "PQRTS1234C" conforms to the specified format:

You might also like