Check if lowercase and uppercase characters are in same order Last Updated : 02 Sep, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given string str containing only lower and uppercase alphabets. The task is to check if both lowercase characters and uppercase characters follow the same order respectively. Note: If a character occurs more than once in lowercase then the occurrence of the same character in the uppercase should be same. Examples: Input: str = "geeGkEEsKS" Output: Yes Lowercase = geeks, Uppercase = GEEKS Input: str = "GeEkKg" Output: No Lowercase = ekg, Uppercase = GEK Approach: Traverse the string.Store the lowercase alphabets and uppercase alphabets in two separate strings lowerStr and upperStr respectively.Convert lowercase string to uppercase.Check if both uppercase strings are equal or not.Print Yes if equal, else print No. Implementation: C++ // C++ program to check if lowercase and // uppercase characters are in same order #include <bits/stdc++.h> using namespace std; // Function to check if both the // case follow the same order bool isCheck(string str) { int len = str.length(); string lowerStr = "", upperStr = ""; // Traverse the string for (int i = 0; i < len; i++) { // Store both lowercase and uppercase // in two different strings if (str[i] >= 65 && str[i] <= 91) upperStr = upperStr + str[i]; else lowerStr = lowerStr + str[i]; } // using transform() function and ::toupper in STL transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(), ::toupper); return lowerStr == upperStr; } // Driver code int main() { string str = "geeGkEEsKS"; isCheck(str) ? cout << "Yes" : cout << "No"; return 0; } Java //Java program to check if lowercase and // uppercase characters are in same order public class GFG { //Function to check if both the //case follow the same order static boolean isCheck(String str) { int len = str.length(); String lowerStr = "", upperStr = ""; char[] str1 = str.toCharArray(); // Traverse the string for (int i = 0; i < len; i++) { // Store both lowercase and uppercase // in two different strings if ((int)(str1[i]) >= 65 && (int)str1[i] <= 91) upperStr = upperStr + str1[i]; else lowerStr = lowerStr + str1[i]; } // transform lowerStr1 to upper String transformStr = lowerStr.toUpperCase(); return(transformStr.equals(upperStr)); } //Driver code public static void main(String[] args) { String str = "geeGkEEsKS"; if (isCheck(str)) System.out.println("Yes"); else System.out.println("No"); } } Python 3 # Python 3 program to Check if lowercase and # uppercase characters are in same order # Function to check if both the # case follow the same order def isCheck(str) : length = len(str) lowerStr, upperStr = "", "" # Traverse the string for i in range(length) : # Store both lowercase and # uppercase in two different # strings if (ord(str[i]) >= 65 and ord(str[i]) <= 91) : upperStr = upperStr + str[i] else : lowerStr = lowerStr + str[i] # transform lowerStr to uppercase transformStr = lowerStr.upper() return transformStr == upperStr # Driver Code if __name__ == "__main__" : str = "geeGkEEsKS" if isCheck(str) : print("Yes") else : print("No") # This code is contributed # by ANKITRAI1 C# // C# program to check if lowercase and // uppercase characters are in same order using System; class GFG { //Function to check if both the //case follow the same order static bool isCheck(string str) { int len = str.Length; string lowerStr = "", upperStr = ""; char[] str1 = str.ToCharArray(); // Traverse the string for (int i = 0; i < len; i++) { // Store both lowercase and uppercase // in two different strings if ((int)(str1[i]) >= 65 && (int)str1[i] <= 91) upperStr = upperStr + str1[i]; else lowerStr = lowerStr + str1[i]; } // transform lowerStr1 to upper String transformStr = lowerStr.ToUpper(); return(transformStr.Equals(upperStr)); } //Driver code public static void Main(String[] args) { String str = "geeGkEEsKS"; if (isCheck(str)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } JavaScript <script> // Javascript program to check if lowercase and // uppercase characters are in same order // Function to check if both the // case follow the same order function isCheck(str) { var len = str.length; var lowerStr = "", upperStr = ""; // Traverse the string for (var i = 0; i < len; i++) { // Store both lowercase and uppercase // in two different strings if (str[i] >= 'A' && str[i] < 'a') upperStr = upperStr + str[i]; else lowerStr = lowerStr + str[i]; } lowerStr = lowerStr.toUpperCase(); console.log(lowerStr); return lowerStr === upperStr; } // Driver code var str = "geeGkEEsKS"; isCheck(str) ? document.write( "Yes") : document.write( "No"); </script> OutputYes Complexity Analysis: Time Complexity: O(len)Auxiliary Space: O(len), where len is the length of the string. Comment More infoAdvertise with us Next Article Count Uppercase, Lowercase, special character and numeric values S Shivam.Pradhan Follow Improve Article Tags : DSA Similar Reads Check if uppercase characters in a string are used correctly or not Given a string S consisting of uppercase and lowercase letters, the task is to check if uppercase characters are used correctly in the given string or not. Correct usage of uppercase characters are as follows: All characters in the string are in uppercase. For example, "GEEKS".None of the characters 8 min read Check string for all uppercase-lowercase or first uppercase and rest lowercase characters Given a string S, the task is to check if all the characters in S are in lowercase, or all the characters are in uppercase or only the first character is in uppercase, and the remaining characters are in lowercase. Print "YES" if any of the condition gets satisfied else print "NO". Examples: Input: 6 min read Count Uppercase, Lowercase, special character and numeric values Given a string, write a program to count the occurrence of Lowercase characters, Uppercase characters, Special characters, and Numeric values. Examples: Input : #GeeKs01fOr@gEEks07 Output : Upper case letters : 5 Lower case letters : 8 Numbers : 4 Special Characters : 2 Input : *GeEkS4GeEkS* Output 5 min read Check if uppercase characters (Capital letters) in a string are used correctly or not | Set 2 Given a string S consisting of uppercase and lowercase letters, the task is to check if uppercase characters are used correctly in the given string or not. Correct usage of uppercase characters are as follows: All characters in the string are in uppercase. For example, âGEEKSâ.None of the characters 5 min read Program to check if first and the last characters of string are equal We are given a string, we need to check whether the first and last characters of the string str are equal or not. Case sensitivity is to be considered. Examples : Input : university Output : Not Equal Explanation: In the string "university", the first character is 'u' and the last character is 'y', 4 min read Check if the characters of a given string are in alphabetical order Given a string 's', the task is to find if the characters of the string are in alphabetical order. The string contains only lowercase characters. Examples: Input: Str = "aabbbcc" Output: In alphabetical order Input: Str = "aabbbcca" Output: Not in alphabetical order A simple approach: Store the stri 14 min read Like