Given an integer N. You can select any two digits from this number (the digits can be same but their positions should be different) and order them in any one of the two possible ways. For each of these ways, you create a two digit number from it (might contain leading zeros). Then, you will pick a character corresponding to the ASCII value equal to this number, i.e. the number 65 corresponds to ‘A’, 66 to ‘B’ and so on. The task is to count the number of english alphabets (lowercase or uppercase) that can be picked in this way.
Input: N = 656
Only the characters ‘A’ (65) and ‘B’ (66) are possible.
Input: N = 1623455078
Approach: The idea is to observe that the total number of possible characters are (26 lowercase + 26 uppercase = 52). So, instead of generating all possible combinations of two digits from N, check the occurrences of these 52 characters.
Therefore, count the occurrences of each digit in N then for every character (lowercase or uppercase), find its ASCII value and check whether it can be picked from the given digits. Print the count of such alphabets in the end.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of numbers upto N digits formed using digits 0 to K-1 without any adjacent 0s
- Count of non decreasing arrays of length N formed with values in range L to R
- Count numbers formed by given two digit with sum having given digits
- Find the count of numbers that can be formed using digits 3, 4 only and having length at max N.
- Program to find the XOR of ASCII values of characters in a string
- Find the sum of the ascii values of characters which are present at prime positions
- Maximum possible time that can be formed from four digits
- Smallest multiple of N formed using the given set of digits
- Minimum sum of two numbers formed from digits of an array in O(n)
- Greatest number less than equal to B that can be formed from the digits of A
- N digit numbers divisible by 5 formed from the M digits
- Check if B can be formed by permuting the binary digits of A
- Minimum sum of two numbers formed from digits of an array
- Count pairs of characters in a string whose ASCII value difference is K
- For each lowercase English alphabet find the count of strings having these alphabets
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Check if the number formed by the last digits of N numbers is divisible by 10 or not
- Recursive sum of digits of a number formed by repeated appends
- Find the largest number that can be formed by changing at most K digits
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.