# Check if lowercase and uppercase characters are in same order

Given a 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
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach:

1. Traverse the string.
2. Store the lowercase alphabets and uppercase alphabets in two separate strings lowerStr and upperStr respectively.
3. Convert lowercase string to uppercase.
4. Check if both uppercase strings are equal or not.
5. Print Yes if equal, else print No.

Below is the implementation of above approach:

## C++

 `// C++ program to check if lowercase and  ` `// uppercase characters are in same order ` `#include ` `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] ` ` `  `    ``# transfor 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"``);  ` `    ``}  ` `}  `

Output:

```Yes
```

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.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.