## The challenge

Compare two strings by comparing the sum of their values (ASCII character code).

• For comparing treat all letters as UpperCase
• `null` should be treated as empty strings
• If the string contains other characters than letters, treat the whole string as it would be empty

Your method should return `true`, if the strings are equal and `false` if they are not equal.

## Examples:

 ``````1 2 3 4 5 6 7 `````` ``````"AD", "BC" -> equal "AD", "DD" -> not equal "gf", "FG" -> equal "zz1", "" -> equal (both are considered empty) "ZzZz", "ffPFF" -> equal "kl", "lz" -> not equal null, "" -> equal ``````

## The solution in Java code

Option 1:

 `````` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 `````` ``````public class Solution { public static boolean compare(String s1, String s2) { if (s1==null || s2==null) return true; s1 = s1.replaceAll(" ", "").toUpperCase().trim(); s2 = s2.replaceAll(" ", "").toUpperCase().trim(); if (s1.length()==0 || s2.length()==0) return true; int s1v = 0; int s2v = 0; for(int i=0;i

Option 2:

 `````` 1 2 3 4 5 6 7 8 9 10 `````` ``````public class Solution { public static boolean compare(String s1, String s2) { if (s1 == null || !s1.matches("[a-zA-Z]+")) s1 = ""; if (s2 == null || !s2.matches("[a-zA-Z]+")) s2 = ""; return s1.toUpperCase().chars().sum() == s2.toUpperCase().chars().sum(); } } ``````

Option 3:

 ``````1 2 3 4 5 6 `````` ``````class Solution { static boolean compare(String s1, String s2) { return (s1 != null && s1.matches("[a-zA-Z]+") ? s1.toUpperCase().chars().sum() : 0) == (s2 != null && s2.matches("[a-zA-Z]+") ? s2.toUpperCase().chars().sum() : 0); } } ``````

## Test cases to validate our solution

 `````` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 `````` ``````import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; public class SolutionTests { @Test public void BasicTests() { assertEquals("'AD' vs 'BC'", true, Solution.compare("AD", "BC")); assertEquals("'AD' vs 'DD'", false, Solution.compare("AD", "DD")); assertEquals("'gf' vs 'FG'", true, Solution.compare("gf", "FG")); assertEquals("'Ad' vs 'DD'", false, Solution.compare("Ad", "DD")); assertEquals("'zz1' vs ''", true, Solution.compare("zz1", "")); assertEquals("'ZzZz' vs 'ffPFF'", true, Solution.compare("ZzZz", "ffPFF")); assertEquals("'kl' vs 'lz'", false, Solution.compare("kl", "lz")); assertEquals("'[null]' vs ''", true, Solution.compare(null, "")); assertEquals("'!!' vs '7476'", true, Solution.compare("!!", "7476")); assertEquals("'##' vs '1176'", true, Solution.compare("##", "1176")); } @Test public void RandomTests() { for(int i=0; i < 40; i++) { char letter1 = (char)(Math.random() * 26 + 65); char letter2 = '1'; do { letter2 = (char)(Math.random() * 26 + 65); } while(letter1 == letter2); if(Math.random() < 0.5) { assertEquals(true, Solution.compare(new String(new char[5]).replace('\0',letter1).toUpperCase() + letter2, letter2 + new String(new char[5]).replace('\0',letter1).toLowerCase())); } if(Math.random() < 0.5) { assertEquals(false, Solution.compare(new String(new char[4]).replace('\0', letter1).toUpperCase() + letter2 + letter2, letter2 + new String(new char[4]).replace('\0', letter1).toLowerCase())); } } } } ``````