Step-by-step solution for Simple Symbols
View the challenge

This challenge requires you to determine if every alphabetic character in a string has a plus (+) symbol on the left and right side of itself. For example: the string "+a+b+c+" is good but the string "===+3+f=+b+" is not because the "f" does not have a plus symbol to its right. A very simple way to solve this challenge is to create a loop that every time it gets to an alphabetic character, it checks to see if it is surrounded by + symbols.

function SimpleSymbols(str) { 

  // pad the strings so that if a character exists at the beginning
  // of the string for example, we don't get on out-of-bounds error by
  // trying to get the character before it
  var str = '=' + str + '=';

  // loop through entire string
  for (var i = 0; i < str.length; i++) {
    
    // check to see if current character is an alphabetic character  
    // by using a simple case-insensitive regex pattern 
    if (str[i].match(/[a-z]/i) !== null) {

      // check to see if a + symbol is to the left and right
      // if not, then we know this string is not valid
      if (str[i-1] !== '+' || str[i+1] !== '+') { 
        return false;
      }

    }
 
  }

  return true;
  
}
   
SimpleSymbols("+d+=3=+s+");                                                                                                
def SimpleSymbols(str): 
  
  # pad the strings so that if a character exists at the beginning
  # of the string for example, we don't get on out-of-bounds error by
  # trying to get the character before it
  str = '=' + str + '='

  # loop through the entire string
  for i in range(0, len(str)):
    
    # check to see if current character is an alphabetic character  
    if str[i].isalpha():

      # check to see if a + symbol is to the left and right
      # if not, then we know this string is not valid
      if str[i-1] != '+' or str[i+1] != '+':
        return 'false'

  return 'true'

print SimpleSymbols("+d+=3=+s+")             
def SimpleSymbols(str)

  # pad the strings so that if a character exists at the beginning
  # of the string for example, we don't get on out-of-bounds error by
  # trying to get the character before it
  str = '=' + str + '='
  
  # loop through the entire string
  (0..str.length - 1).each do |i|

    # check to see if current character is an alphabetic character 
    if str[i] =~ /[A-Za-z]/

      # check to see if a + symbol is to the left and right
      # if not, then we know this string is not valid
      if str[i - 1] != '+' || str[i + 1] != '+'
        return 'false'
      end

    end

  end
  
  return 'true'
         
end
    
puts SimpleSymbols(STDIN.gets)              
Top User Solutions
1 hyuil Challenge Score: 10 Cpp
1 Qlogin Challenge Score: 9 Python
2 Sabin Challenge Score: 10 Python
1 emuchynski Challenge Score: 10 Ruby
2 junjunparkpark Challenge Score: 10 Ruby
1 cjordanball Challenge Score: 10 JavaScript
3 Corinto Challenge Score: 10 Python
2 EmperorDuny Challenge Score: 10 JavaScript
4 gzamfire Challenge Score: 10 Python
5 mmalkavian Challenge Score: 10 Python
3 GarenLiang Challenge Score: 10 JavaScript
2 lokeshmogra Challenge Score: 10 Cpp
6 cdms0 Challenge Score: 10 Python
4 beeboop19 Challenge Score: 10 JavaScript
5 jackgeek Challenge Score: 10 JavaScript
6 escapiststupor Challenge Score: 10 JavaScript
7 scates Challenge Score: 10 Python
7 chrigolex Challenge Score: 9 JavaScript
8 philtroin Challenge Score: 10 Python
8 mattlarsh Challenge Score: 10 JavaScript
9 deuzen Challenge Score: 10 JavaScript
1 arjnklc Challenge Score: 10 Java
10 SuprDewd Challenge Score: 10 JavaScript
3 gutty333 Challenge Score: 10 Cpp
4 theBestFella Challenge Score: 10 Cpp
3 Bohdan Challenge Score: 10 Ruby
4 toasterbob Challenge Score: 10 Ruby
9 Abualleaf Challenge Score: 10 Python
10 Yosejimyte Challenge Score: 9 Python
5 duncanbb Challenge Score: 10 Ruby
6 mattfara Challenge Score: 10 Ruby
7 kelaiyarao1 Challenge Score: 10 Ruby
5 johne Challenge Score: 10 Cpp
8 randyjap Challenge Score: 10 Ruby
9 johncoleman83 Challenge Score: 9 Ruby
1 ionutforyou Challenge Score: 10 PHP
6 Justification Challenge Score: 10 Cpp
10 CoderAPS Challenge Score: 10 Ruby
2 tostercx Challenge Score: 10 PHP
7 Zeikar Challenge Score: 10 Cpp
2 danaksim Challenge Score: 10 Java
3 jakmaj Challenge Score: 10 Java
4 mikejagen Challenge Score: 10 Java
5 ph4ntom Challenge Score: 10 Java
6 binfeng Challenge Score: 10 Java
8 anta0 Challenge Score: 10 Cpp
9 lingqyzeng Challenge Score: 9 Cpp
10 amatakos Challenge Score: 10 Cpp
7 k8conant Challenge Score: 10 Java
8 nicklivens Challenge Score: 10 Java
9 KSmithson Challenge Score: 10 Java
10 kester824 Challenge Score: 10 Java
3 longcheng Challenge Score: 10 PHP
4 torbjornperttu Challenge Score: 10 PHP
5 albionselimaj Challenge Score: 10 PHP
6 teplicko Challenge Score: 10 PHP
7 Althalus Challenge Score: 9 PHP
8 smcdowell Challenge Score: 10 PHP
9 jetonr Challenge Score: 10 PHP
10 copacubanana Challenge Score: 10 PHP

Become a Premium Member

With our large collection of challengs, tutorials, and solutions, we make it easy for you to become a better coder, prepare for interviews, and learn new skills from more experienced coders.

“Also important to try coding in nonstructured or semistructured environments to see if you like it. Coderbyte really helped me.“ ― Jeff Ruder
  • 200+ Coding Challenges
  • Mock Interview Questions
  • 500,000+ Code Solutions
  • Algorithm Tutorials
  • Interview Prep Courses