Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Natural Numbers
  • Whole Numbers
  • Real Numbers
  • Integers
  • Rational Numbers
  • Irrational Numbers
  • Complex Numbers
  • Prime Numbers
  • Odd Numbers
  • Even Numbers
  • Properties of Numbers
  • Number System
Open In App
Next Article:
Make all characters of a string same by minimum number of increments or decrements of ASCII values of characters
Next article icon

Count strings having sum of ASCII values of characters equal to a Prime or Armstrong Number

Last Updated : 08 Feb, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Given an array arr[] of size N containing strings, the task is to count the number of strings having the sum of ASCII (American Standard Code for Information Interchange) values of characters equal to an Armstrong Number number or a Prime Number.

Examples:

Input: arr[] = {“hello”, “nace”}
Output:
Number of Armstrong Strings are: 1
Number of Prime Strings are: 0
Explanation: Sum of ASCII values of characters of each string is: {532, 407}, out of which 407 is an Armstrong Number, and none of them is a Prime Number.
Hence, the armstrong valued string is “nace”.

Input: arr[] = {“geeksforgeeks”, “a”, “computer”, “science”, “portal”, “for”, “geeks”}
Output:
Number of Armstrong Strings are: 0
Number of Prime Strings are: 2 
Explanation: Sum of ASCII values of characters of each string is: {1381, 97, 879, 730, 658, 327, 527}, out of which 1381 and 97 are Prime Numbers, and none of them is an Armstrong Number.
Hence, prime valued strings are “geeksforgeeks” and “a”.

Approach: This problem can be solved by calculating the ASCII value of each string. Follow the steps below to solve this problem:

  • Initialize two variables, countPrime and countArmstrong as 0, to store the count of Prime and Armstrong valued strings.
  • Iterate over the range of indices [0, N – 1] using a variable, say i and perform the following steps: 
    • Store the sum of ASCII values of characters of the current string arr[i] in a variable, say val.
    • If the number val is an Armstrong Number, increment countArmstrong by 1.
    • If the number val is a Prime Number, increment countPrime by 1.
  • Print the values of countPrime and countArmstrong as the result.

Below is the implementation of the above approach:

C++




// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
 
// Function to check if a
// number is prime number
bool isPrime(int num)
{
     
    // Define a flag variable
    bool flag = false;
 
    if (num > 1)
    {
         
        // Check for factors of num
        for(int i = 2; i < num; i++)
        {
             
            // If factor is found,
            // set flag to True and
            // break out of loop
            if ((num % i) == 0)
            {
                flag = true;
                break;
            }
        }
    }
 
    // Check if flag is True
    if (flag)
        return false;
    else
        return true;
}
 
// Function to calculate
// order of the number x
int order(int x)
{
    int n = 0;
    while (x != 0)
    {
        n = n + 1;
        x = x / 10;
    }
    return n;
}
 
// Function to check whether the given
// number is Armstrong number or not
bool isArmstrong(int x)
{
    int n = order(x);
    int temp = x;
    int sum1 = 0;
 
    while (temp != 0)
    {
        int r = temp % 10;
        sum1 = sum1 + pow(r, n);
        temp = temp / 10;
    }
     
    // If the condition satisfies
    return (sum1 == x);
}
 
// Function to count
// Armstrong valued strings
int count_armstrong(vector<string> li)
{
     
    // Stores the count of
    // Armstrong valued strings
    int c = 0;
 
    // Iterate over the list
    for(string ele : li)
    {
         
        // Store the value
        // of the string
        int val = 0;
 
        // Find value of the string
        for(char che:ele)
            val += che;
 
        // Check if it an Armstrong number
        if (isArmstrong(val))
            c += 1;
    }
    return c;
}
 
// Function to count
// prime valued strings
int count_prime(vector<string> li)
{
     
    // Store the count of
    // prime valued strings
    int c = 0;
 
    // Iterate over the list
    for(string ele:li)
    {
         
        // Store the value
        // of the string
        int val = 0;
 
        // Find value of the string
        for(char che : ele)
            val += che;
 
        // Check if it
        // is a Prime Number
        if (isPrime(val))
            c += 1;
    }
    return c;
}
 
// Driver code
int main()
{
    vector<string> arr = { "geeksforgeeks", "a", "computer",
                           "science", "portal", "for", "geeks"};
     
    // Function Call
    cout << "Number of Armstrong Strings are: "
         << count_armstrong(arr) << endl;
    cout << "Number of Prime Strings are: "
         << count_prime(arr) << endl;
}
 
// This code is contributed by mohit kumar 29
 
 

Java




// Java program for the above approach
import java.io.*;
 
class GFG {
     
    // Function to check if a
    // number is prime number
    static boolean isPrime(int num)
    {
  
        // Define a flag variable
        boolean flag = false;
  
        if (num > 1) {
  
            // Check for factors of num
            for (int i = 2; i < num; i++) {
  
                // If factor is found,
                // set flag to True and
                // break out of loop
                if ((num % i) == 0) {
                    flag = true;
                    break;
                }
            }
        }
  
        // Check if flag is True
        if (flag)
            return false;
        else
            return true;
    }
  
    // Function to calculate
    // order of the number x
    static int order(int x)
    {
        int n = 0;
        while (x != 0) {
            n = n + 1;
            x = x / 10;
        }
        return n;
    }
  
    // Function to check whether the given
    // number is Armstrong number or not
    static boolean isArmstrong(int x)
    {
        int n = order(x);
        int temp = x;
        int sum1 = 0;
  
        while (temp != 0) {
            int r = temp % 10;
            sum1 = sum1 + (int)(Math.pow(r, n));
            temp = temp / 10;
        }
  
        // If the condition satisfies
        return (sum1 == x);
    }
  
    // Function to count
    // Armstrong valued strings
    static int count_armstrong(String[] li)
    {
  
        // Stores the count of
        // Armstrong valued strings
        int c = 0;
  
        // Iterate over the list
        for(String ele : li)
        {
  
            // Store the value
            // of the string
            int val = 0;
  
            // Find value of the string
            for(char che : ele.toCharArray()) val += che;
  
            // Check if it an Armstrong number
            if (isArmstrong(val))
                c += 1;
        }
        return c;
    }
  
    // Function to count
    // prime valued strings
    static int count_prime(String[] li)
    {
  
        // Store the count of
        // prime valued strings
        int c = 0;
  
        // Iterate over the list
        for(String ele : li)
        {
  
            // Store the value
            // of the string
            int val = 0;
  
            // Find value of the string
            for(char che : ele.toCharArray()) val += che;
  
            // Check if it
            // is a Prime Number
            if (isPrime(val))
                c += 1;
        }
        return c;
    }
  
    // Driver code
     
    public static void main (String[] args) {
        String[] arr
            = { "geeksforgeeks", "a",      "computer",
                "science",       "portal", "for",
                "geeks" };
  
        // Function Call
        System.out.println(
            "Number of Armstrong Strings are: "
            + count_armstrong(arr));
        System.out.println("Number of Prime Strings are: "
                          + count_prime(arr));
    }
}
 
// This code is contributed by patel2127.
 
 

Python3




# Python program for the above approach
 
# Function to check if a
# number is prime number
def isPrime(num):
 
    # Define a flag variable
    flag = False
 
    if num > 1:
 
        # Check for factors of num
        for i in range(2, num):
 
            # If factor is found,
            # set flag to True and
            # break out of loop
            if (num % i) == 0:
                flag = True
                break
 
    # Check if flag is True
    if flag:
        return False
    else:
        return True
 
# Function to calculate
# order of the number x
def order(x):
    n = 0
    while (x != 0):
        n = n + 1
        x = x // 10
    return n
 
# Function to check whether the given
# number is Armstrong number or not
def isArmstrong(x):
    n = order(x)
    temp = x
    sum1 = 0
 
    while (temp != 0):
 
        r = temp % 10
        sum1 = sum1 + r**n
        temp = temp // 10
 
    # If the condition satisfies
    return (sum1 == x)
 
# Function to count
# Armstrong valued strings
def count_armstrong(li):
 
    # Stores the count of
    # Armstrong valued strings
    c = 0
 
    # Iterate over the list
    for ele in li:
 
        # Store the value
        # of the string
        val = 0
         
        # Find value of the string
        for che in ele:
            val += ord(che)
             
        # Check if it an Armstrong number
        if isArmstrong(val):
            c += 1
    return c
 
# Function to count
# prime valued strings
def count_prime(li):
     
    # Store the count of
    # prime valued strings
    c = 0
     
    # Iterate over the list
    for ele in li:
       
        # Store the value
        # of the string
        val = 0
         
        # Find value of the string
        for che in ele:
            val += ord(che)
             
        # Check if it
        # is a Prime Number
        if isPrime(val):
            c += 1
    return c
 
 
# Driver code
arr = ["geeksforgeeks", "a", "computer",
       "science", "portal", "for", "geeks"]
 
# Function Call
print("Number of Armstrong Strings are:", count_armstrong(arr))
print("Number of Prime Strings are:", count_prime(arr))
 
 

C#




// C# program for the above approach
using System;
using System.Collections.Generic;
class GFG
{
   
    // Function to check if a
    // number is prime number
    static bool isPrime(int num)
    {
 
        // Define a flag variable
        bool flag = false;
 
        if (num > 1) {
 
            // Check for factors of num
            for (int i = 2; i < num; i++) {
 
                // If factor is found,
                // set flag to True and
                // break out of loop
                if ((num % i) == 0) {
                    flag = true;
                    break;
                }
            }
        }
 
        // Check if flag is True
        if (flag)
            return false;
        else
            return true;
    }
 
    // Function to calculate
    // order of the number x
    static int order(int x)
    {
        int n = 0;
        while (x != 0) {
            n = n + 1;
            x = x / 10;
        }
        return n;
    }
 
    // Function to check whether the given
    // number is Armstrong number or not
    static bool isArmstrong(int x)
    {
        int n = order(x);
        int temp = x;
        int sum1 = 0;
 
        while (temp != 0) {
            int r = temp % 10;
            sum1 = sum1 + (int)(Math.Pow(r, n));
            temp = temp / 10;
        }
 
        // If the condition satisfies
        return (sum1 == x);
    }
 
    // Function to count
    // Armstrong valued strings
    static int count_armstrong(string[] li)
    {
 
        // Stores the count of
        // Armstrong valued strings
        int c = 0;
 
        // Iterate over the list
        foreach(string ele in li)
        {
 
            // Store the value
            // of the string
            int val = 0;
 
            // Find value of the string
            foreach(char che in ele) val += che;
 
            // Check if it an Armstrong number
            if (isArmstrong(val))
                c += 1;
        }
        return c;
    }
 
    // Function to count
    // prime valued strings
    static int count_prime(string[] li)
    {
 
        // Store the count of
        // prime valued strings
        int c = 0;
 
        // Iterate over the list
        foreach(string ele in li)
        {
 
            // Store the value
            // of the string
            int val = 0;
 
            // Find value of the string
            foreach(char che in ele) val += che;
 
            // Check if it
            // is a Prime Number
            if (isPrime(val))
                c += 1;
        }
        return c;
    }
 
    // Driver code
    public static void Main()
    {
        string[] arr
            = { "geeksforgeeks", "a",      "computer",
                "science",       "portal", "for",
                "geeks" };
 
        // Function Call
        Console.WriteLine(
            "Number of Armstrong Strings are: "
            + count_armstrong(arr));
        Console.WriteLine("Number of Prime Strings are: "
                          + count_prime(arr));
    }
}
 
// This code is contributed by ukasp.
 
 

Javascript




<script>
 
// JavaScript program for the above approach
 
// Function to check if a
// number is prime number
function isPrime(num) {
 
    // Define a flag variable
    let flag = false;
 
    if (num > 1) {
 
        // Check for factors of num
        for (let i = 2; i < num; i++) {
 
            // If factor is found,
            // set flag to True and
            // break out of loop
            if ((num % i) == 0) {
                flag = true;
                break;
            }
        }
    }
 
    // Check if flag is True
    if (flag)
        return false;
    else
        return true;
}
 
// Function to calculate
// order of the number x
function order(x) {
    let n = 0;
    while (x != 0) {
        n = n + 1;
        x = x / 10;
    }
    return n;
}
 
// Function to check whether the given
// number is Armstrong number or not
function isArmstrong(x) {
    let n = order(x);
    let temp = x;
    let sum1 = 0;
 
    while (temp != 0) {
        let r = temp % 10;
        sum1 = sum1 + Math.pow(r, n);
        temp = temp / 10;
    }
 
    // If the condition satisfies
    return (sum1 == x);
}
 
// Function to count
// Armstrong valued strings
function count_armstrong(li) {
 
    // Stores the count of
    // Armstrong valued strings
    let c = 0;
 
    // Iterate over the list
    for (let ele of li) {
 
        // Store the value
        // of the string
        let val = 0;
 
        // Find value of the string
        for (let che of ele)
            val += che.charCodeAt(0);
 
        // Check if it an Armstrong number
        if (isArmstrong(val))
            c += 1;
    }
    return c;
}
 
// Function to count
// prime valued strings
function count_prime(li) {
 
    // Store the count of
    // prime valued strings
    let c = 0;
 
    // Iterate over the list
    for (let ele of li) {
 
        // Store the value
        // of the string
        let val = 0;
 
        // Find value of the string
        for (let che of ele)
            val += che.charCodeAt(0);
 
        // Check if it
        // is a Prime Number
        if (isPrime(val))
            c += 1;
    }
    return c;
}
 
// Driver code
 
let arr = ["geeksforgeeks", "a", "computer",
    "science", "portal", "for", "geeks"];
 
// Function Call
document.write("Number of Armstrong Strings are: "
    + count_armstrong(arr) + "<br>");
document.write("Number of Prime Strings are: "
    + count_prime(arr) + "<br>");
 
 
// This code is contributed by gfgking
 
</script>
 
 
Output
Number of Armstrong Strings are: 0 Number of Prime Strings are: 2 

Time Complexity: O(N*M), where M is the length of the longest string in the array arr[]
Auxiliary Space: O(1)



Next Article
Make all characters of a string same by minimum number of increments or decrements of ASCII values of characters
author
santhoshcharan
Improve
Article Tags :
  • Arrays
  • DSA
  • Mathematical
  • Strings
  • ASCII
  • Numbers
  • Prime Number
Practice Tags :
  • Arrays
  • Mathematical
  • Numbers
  • Prime Number
  • Strings

Similar Reads

  • What is ASCII - A Complete Guide to Generating ASCII Code
    The American Standard Code for Information Interchange, or ASCII, is a character encoding standard that has been a foundational element in computing for decades. It plays a crucial role in representing text and control characters in digital form. Historical BackgroundASCII has a rich history, dating
    13 min read
  • ASCII Values Alphabets ( A-Z, a-z & Special Character Table )
    ASCII (American Standard Code for Information Interchange) is a standard character encoding used in telecommunication. The ASCII pronounced 'ask-ee', is strictly a seven-bit code based on the English alphabet. ASCII codes are used to represent alphanumeric data. The code was first published as a sta
    7 min read
  • ASCII Vs UNICODE
    Overview :Unicode and ASCII are the most popular character encoding standards that are currently being used all over the world. Unicode is the universal character encoding used to process, store and facilitate the interchange of text data in any language while ASCII is used for the representation of
    3 min read
  • ASCII Value of a Character in C
    In this article, we will discuss about the ASCII values that are bit numbers used to represent the character in the C programming language. We will also discuss why the ASCII values are needed and how to find the ASCII value of a given character in a C program. Table of Content What is ASCII Value o
    4 min read
  • ascii() in Python
    Python ascii() function returns a string containing a printable representation of an object and escapes the non-ASCII characters in the string using \x, \u or \U escapes. It's a built-in function that takes one argument and returns a string that represents the object using only ASCII characters. Exa
    3 min read
  • Program to Print ASCII Conversion

    • Program to print ASCII Value of all digits of a given number
      Given an integer N, the task is to print the ASCII value of all digits of N. Examples: Input: N = 8Output: 8 (56)Explanation:ASCII value of 8 is 56 Input: N = 240Output:2 (50)4 (52)0 (48) Approach: Using the ASCII table shown below, the ASCII value of all the digits of N can be printed: DigitASCII V
      5 min read

    • Program to print ASCII Value of a character
      Given a character, we need to print its ASCII value in C/C++/Java/Python. Examples : Input : a Output : 97 Input : DOutput : 68 Here are few methods in different programming languages to print ASCII value of a given character :  Python code using ord function : ord() : It converts the given string o
      4 min read

    • Print given sentence into its equivalent ASCII form
      Given a string containing words forming a sentence (belonging to the English language). The task is to output the equivalent ASCII sentence of the input sentence. ASCII (American Standard Code for Information Interchange) form of a sentence is the conversion of each of the characters of the input st
      4 min read

    • Count and Print the alphabets having ASCII value not in the range [l, r]
      Given a string str, the task is to count the number of alphabets having ASCII values, not in the range [l, r]. Examples: Input: str = "geeksforgeeks", l = 102, r = 111Output: Count = 7Characters - e, s, r have ASCII values not in the range [102, 111]. Input: str = "GeEkS", l = 80, r = 111Output: Cou
      6 min read

    • Print each word in a sentence with their corresponding average of ASCII values
      Given a sentence, the task is to find the average of ASCII values of each word in the sentence and print it with the word. Examples: Input: sentence = "Learning a string algorithm"Output:Learning - 102a - 97string - 110algorithm - 107 Approach: Take an empty string and start traversing the sentence
      6 min read

    Program for Binary to ASCII Conversion

    • Python program to convert binary to ASCII
      In this article, we are going to see the conversion of Binary to ASCII in the Python programming language. There are multiple approaches by which this conversion can be performed that are illustrated below: Method 1: By using binascii module Binascii helps convert between binary and various ASCII-en
      3 min read

    • Program to convert given Binary to its equivalent ASCII character string
      Given a binary string str, the task is to find its equivalent ASCII (American Standard Code for Information Interchange) character string. Examples: Input: str = "0110000101100010"Output: abExplanation: Dividing str into set of 8 bits as follows: 01100001 = 97, ASCII value of 97 is 'a'.01100010 = 98
      9 min read

    Problem Related to ASCCI

    • Program to Convert ASCII to Unicode
      In this article, we will learn about different character encoding techniques which are ASCII (American Standard Code for Information Interchange) and Unicode (Universal Coded Character Set), and the conversion of ASCII to Unicode. Table of Content What is ASCII Characters?What is ASCII Table?What is
      4 min read

    • Program to Convert Unicode to ASCII
      Given a Unicode number, the task is to convert this into an ASCII (American Standard Code for Information Interchange) number. ASCII numberASCII is a character encoding standard used in communication systems and computers. It uses 7-bit encoding to encode 128 different characters 0-127. These values
      4 min read

    • Program to implement ASCII lookup table
      ASCII stands for American Standard Code for Information Interchange. Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as ‘a’ or ‘@’ or an action of some sort. ASCII lookup table is a tabular representation of corresponding values associated
      7 min read

    • Program to find the product of ASCII values of characters in a string
      Given a string str. The task is to find the product of ASCII values of characters in the string. Examples: Input: str = "IS"Output: 605973 * 83 = 6059 Input: str = "GfG"Output: 514182 The idea is to start with iterating through characters of the string and multiply their ASCII values to a variable n
      4 min read

    • How to convert character to ASCII code using JavaScript ?
      The purpose of this article is to get the ASCII code of any character by using JavaScript charCodeAt() method. This method is used to return the number indicating the Unicode value of the character at the specified index. Syntax: string.charCodeAt(index); Example: Below code illustrates that they ca
      1 min read

    • Converting an Integer to ASCII Characters in Python
      In Python, working with integers and characters is a common task, and there are various methods to convert an integer to ASCII characters. ASCII (American Standard Code for Information Interchange) is a character encoding standard that represents text in computers. In this article, we will explore s
      2 min read

    • Check if a string contains uppercase, lowercase, special characters and numeric values
      Given string str of length N, the task is to check whether the given string contains uppercase alphabets, lowercase alphabets, special characters, and numeric values or not. If the string contains all of them, then print "Yes". Otherwise, print "No". Examples: Input: str = "#GeeksForGeeks123@" Outpu
      5 min read

    • How to remove all non-alphanumeric characters from a string in Java
      Given string str, the task is to remove all non-alphanumeric characters from it and print the modified it. Examples: Input: @!Geeks-for'Geeks,123 Output: GeeksforGeeks123 Explanation: at symbol(@), exclamation point(!), dash(-), apostrophes('), and commas(, ) are removed.Input: Geeks_for$ Geeks?{}[]
      3 min read

    • Convert the ASCII value sentence to its equivalent string
      Given a string str which represents the ASCII (American Standard Code for Information Interchange) Sentence, the task is to convert this string into its equivalent character sequence. Examples: Input: str = "71101101107115" Output: Geeks 71, 101, 101, 107 are 115 are the unicode values of the charac
      5 min read

    • Check whether the given character is in upper case, lower case or non alphabetic character
      Given a character, the task is to check whether the given character is in upper case, lower case, or non-alphabetic character Examples: Input: ch = 'A'Output: A is an UpperCase characterInput: ch = 'a'Output: a is an LowerCase characterInput: ch = '0'Output: 0 is not an alphabetic characterApproach:
      11 min read

    • Average of ASCII values of characters of a given string
      Given a string, the task is to find the average of ASCII values of characters in the string. Examples: Input: str = "for"Output: 109'f'= 102, 'o' = 111, 'r' = 114(102 + 111 + 114)/3 = 109 Input: str = "geeks" Output: 105 Source: Microsoft Internship Experience Approach: Start iterating through chara
      5 min read

    • Sums of ASCII values of each word in a sentence
      We are given a sentence of English language(can also contain digits), we need to compute and print the sum of ASCII values of characters of each word in that sentence. Examples: Input : GeeksforGeeks, a computer science portal for geeksOutput : Sentence representation as sum of ASCII each character
      7 min read

    • Program to find the largest and smallest ASCII valued characters in a string
      Given a string of lowercase and uppercase characters, your task is to find the largest and smallest alphabet (according to ASCII values) in the string. Note that in ASCII, all capital letters come before all small letters. Examples : Input : sample stringOutput : Largest = t, Smallest = aInput : Gee
      6 min read

    • Count characters in a string whose ASCII values are prime
      Given a string S. The task is to count and print the number of characters in the string whose ASCII values are prime. Examples: Input: S = "geeksforgeeks" Output : 3 'g', 'e' and 'k' are the only characters whose ASCII values are prime i.e. 103, 101 and 107 respectively. Input: S = "abcdefghijklmnop
      6 min read

    • Check for ASCII String - Python
      To check if a string contains only ASCII characters, we ensure all characters fall within the ASCII range (0 to 127). This involves comparing each character's value to ensure it meets the criteria. Using str.isascii()The simplest way to do this in Python is by using the built-in str.isascii() method
      2 min read

    • Check if a String Contains Only Alphabets in Java using ASCII Values
      Given a string, now we all know that the task is to check whether a string contains only alphabets. Now we will be iterating character by character and checking the corresponding ASCII value attached to it. If not found means there is some other character other than "a-z" or "A-Z". If we traverse th
      4 min read

    • Map function and Dictionary in Python to sum ASCII values
      We are given a sentence in the English language(which can also contain digits), and we need to compute and print the sum of ASCII values of the characters of each word in that sentence. Examples: Input : GeeksforGeeks, a computer science portal for geeksOutput : Sentence representation as sum of ASC
      2 min read

    • Count of camel case characters present in a given string
      Given a string S, the task is to count the number of camel case characters present in the given string. The camel case character is defined as the number of uppercase characters in the given string. Examples: Input: S = "ckjkUUYII"Output: 5Explanation: Camel case characters present are U, U, Y, I an
      7 min read

    • Sort an array of strings in increasing order of sum of ASCII values of characters
      Given an array arr[] consisting of N strings, the task is to sort the strings in increasing order of the sum of the ASCII (American Standard Code for Information Interchange) value of their characters. Examples: Input: arr[] = {"for", "geeks", "app", "best"}Output: app for best geeksExplanation:Sum
      7 min read

    • Count pairs of characters in a string whose ASCII value difference is K
      Given string str of lower case alphabets and a non-negative integer K. The task is to find the number of pairs of characters in the given string whose ASCII value difference is exactly K. Examples: Input: str = "abcdab", K = 0 Output: 2 (a, a) and (b, b) are the only valid pairs.Input: str = "geeksf
      7 min read

    • Count of alphabets having ASCII value less than and greater than k
      Given a string, the task is to count the number of alphabets having ASCII values less than and greater than or equal to a given integer k. Examples: Input: str = "GeeksForGeeks", k = 90Output:3, 10G, F, G have ascii values less than 90.e, e, k, s, o, r, e, e, k, s have ASCII values greater than or e
      11 min read

    • Count strings having sum of ASCII values of characters equal to a Prime or Armstrong Number
      Given an array arr[] of size N containing strings, the task is to count the number of strings having the sum of ASCII (American Standard Code for Information Interchange) values of characters equal to an Armstrong Number number or a Prime Number. Examples: Input: arr[] = {"hello", "nace"}Output:Numb
      12 min read

    • Make all characters of a string same by minimum number of increments or decrements of ASCII values of characters
      Given a string S of length N, the task is to make all characters of the string the same by incrementing/decrementing the ASCII value of any character by 1 any number of times. Note: All characters must be changed to a character of the original string. Examples: Input: S = "geeks"Output: 20Explanatio
      6 min read

    • Minimize swaps of same-indexed characters to make sum of ASCII value of characters of both the strings odd
      Given two N-length strings S and T consisting of lowercase alphabets, the task is to minimize the number of swaps of the same indexed elements required to make the sum of the ASCII value of characters of both the strings odd. If it is not possible to make the sum of ASCII values odd, then print "-1"
      9 min read

    • Count the number of words having sum of ASCII values less than and greater than k
      Given a string, the task is to count the number of words whose sum of ASCII values is less than and greater than or equal to given k. Examples: Input: str = "Learn how to code", k = 400Output:Number of words having the sum of ASCII less than k = 2Number of words having the sum of ASCII greater than
      11 min read

    • Minimum cost to make the String palindrome using ASCII values
      Given an input string S, the task is to make it a palindrome and calculate the minimum cost for making it a palindrome, where you are allowed to use any one of the following operations any number of times: For replacing the current character with another character the cost will be the absolute diffe
      5 min read

    • Find frequency of each digit 0-9 by concatenating ASCII values of given string
      Given string str, the task is to find the frequency of all digits (0-9) in a string created by concatenating the ASCII values of each character of the given string str. Example: Input: str = "GeeksForGeeks"Output: 7 21 0 0 1 2 0 5 0 0Explanation: The array of ASCII values of all characters of the gi
      5 min read

    • Super ASCII String Checker | TCS CodeVita
      In the Byteland country, a string S is said to super ASCII string if and only if the count of each character in the string is equal to its ASCII value. In the Byteland country ASCII code of 'a' is 1, 'b' is 2, ..., 'z' is 26. The task is to find out whether the given string is a super ASCII string o
      8 min read

geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences