HackerRank Python - Piling Up


When stacking the cubes, you can only pick up either the leftmost or the rightmost cube each time. Print "Yes" if it is possible to stack the cubes. Otherwise, print "No". Do not print the quotation marks.

  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. for t in range(int(input())):
  3. l = int(input())
  4. sides = list(map(int, input().split()))
  5. i = 0
  6. while i < l - 1 and sides[i] >= sides[i + 1]:
  7. i += 1
  8. while i < l - 1 and sides[i] <= sides[i + 1]:
  9. i += 1
  10. print('Yes' if i == l - 1 else 'No')

download android app