title: Why is this code not valid for all the cases?
body: <p>I am trying to solve <a href="https://www.hackerrank.com/challenges/piling-up/problem" rel="nofollow noreferrer">this</a> problem on hacker rank:</p>
  
  <p>Here is my code:</p>
  
  <pre><code>L = []
  check = True
  num_cases = int(input())
  for i in range(num_cases):
      num_cubes = int(input())
      inp = input()
      L = inp.split(" ")
      for m in range(0, len(L)):
          L[m] = int(L[m])    
      while len(L) != 1:
          x = max(L)
          if L.count(x) &lt;= 2:
              if x == L[0] or x == L[-1]:
                  while x in L:
                      L.remove(x)
              else:
                  check = False
                  break
          else:
              check = False
              break
      if check == False:
          print("No")
      else:
          print("Yes")
      L = []
      check = True
  </code></pre>
  
  <p>Here I check if the maximum values of the list lie on either end of the list.</p>
  
  <p>This code is working for all the cases that I have given it but works for none of the cases that the website gives it.</p>
  
  <p>Test case 1: <a href="https://hr-testcases-us-east-1.s3.amazonaws.com/8380/input01.txt?AWSAccessKeyId=AKIAJ4WZFDFQTZRGO3QA&amp;Expires=1580298925&amp;Signature=IPucdSUZfTvhCAuntcEGKDIfgP4%3D&amp;response-content-type=text%2Fplain" rel="nofollow noreferrer">Here</a></p>
  
  <p>Expected solution to test case 1: <a href="https://hr-testcases-us-east-1.s3.amazonaws.com/8380/output01.txt?AWSAccessKeyId=AKIAJ4WZFDFQTZRGO3QA&amp;Expires=1580300646&amp;Signature=AVAzPxvxQt5qNtUwV%2BEBlw8FT3w%3D&amp;response-content-type=text%2Fplain" rel="nofollow noreferrer">Here</a></p>
  
  <p>PS. please inform me if I need to edit my question in any way.</p>