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')




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube