title: Google Foobar - Please Pass The Coded Message Test Case Failure
body: <h2>Question</h2>
  <p>You have L, a list containing some digits (0 to 9). Write a function solution(L) which finds the largest number that can be made from some or all of these digits and is divisible by 3.</p>
  <p>If it is not possible to make such a number, return 0 as the solution. L will contain anywhere from 1 to 9 digits.  The same digit may appear multiple times in the list, but each element in the list may only be used once.</p>
  <h2>Test Cases</h2>
  <p>Input:
  solution.solution([3, 1, 4, 1])
  Output:
  4311</p>
  <p>Input:
  solution.solution([3, 1, 4, 1, 5, 9])
  Output:
  94311</p>
  <h2>My code</h2>
  <pre class="lang-py prettyprint-override"><code>
  def sum(L):
      totalSum = 0
      for x in range(len(L)):
          totalSum = totalSum + L[x]
          
      return totalSum 
  
  def listToInteger(L):
      strings = [str(integer) for integer in L ]
      concatString = &quot;&quot;.join(strings)
      finalInt = int(concatString)
      return finalInt
  
  
  def solution(L):  
      
      num = sum(L)
      
      if not num % 3:
          L.sort(reverse=True) # sort list in descending order to create largest number
          return listToInteger(L)
      
      else:
          n = num % 3
          flag = False
         
          
      while not flag: # locate digit causing indivisiblity
          if n in L:
              L.remove(n)
              L.sort(reverse=True)
              return listToInteger(L)
  
          elif(n &gt; num):
              return 0
             
          else:
              n += 3
  </code></pre>
  <p>I get the two test cases correct, but there is one hidden case that keeps failing. I'm not sure if the input is not strict enough, or if there is a fault in my logic</p>
  <p>the only fault in logic I can think of is if the input was [8,5,3] , the sum would be 16 and 16 % 3 = 1</p>
  <p>so it would check the list for 1, 4, 7, 10, 13 , 16 but it wouldnt be in the list so it wouldn't remove 8 or 5. it would return 0 when it should actually return [3].</p>
  <p>I added a function for this but even then it was still failing the hidden test case. . .</p>
  <p>Any suggestions would be appreciated</p>