Problem · String

Compute Difference Between Uppercase and Lowercase Letters

Learn this problem
EasyMeta logoMetaINTERNOA
See Meta hiring insights

Problem statement

Note ->> See the Image Source section at the very bottom of the page for the original problem statement and etc.. 🐰🐰

100 years agoo0, a typing practice app wanted to test how well users balanced uppercase and lowercase letters in their entries. For every string a user typed, the app needed to count the number of uppercase and lowercase letters and calculate the difference between them—positive if uppercase dominated, negative if lowercase took the lead. It didn’t mind if the solution wasn’t the most efficient, as long as it could handle the text without breaking a sweat, even if it meant checking some letters more than once. With your help, the app could ensure everything stayed consistent and fun!

𓍢ִ໋🌷͙֒ ᩚMany thanks to Charlotte babyᰔ

Function

computeDiff(text: String) → int

Examples

Example 1

text = "CodeSignal"return = -6
In the given text, there are 2 uppercase letters ('C' and 'S') and 8 lowercase letters ('o', 'd', 'e', 'S', 'i', 'g', 'n', 'a', 'l'). This results in a difference of 2 - 8 = -6.

Example 2

text = "a"return = -1
The text contains just 1 lowercase letter ('a') and no uppercase letters. So, the difference is 0 - 1 = -1.

Constraints

  • 0 ≤ typedText.length ≤ 100.

More Meta problems

drafts saved locally
public int computeDiff(String text) {
  // write your code here
}
text"CodeSignal"
expected-6
checking account