You are not logged in. Please login at www.codechef.com to post your questions!

×

RAINBOWA python code wrong output

here is my python code:

code

q="1234567"

k=[]

function to omit test cases like 2 1 3 4 5 6 7 6 5 4 3 1 2

def is_increasing(n):

for i in range(int(len(n)/2)):


    if n[i]>n[i+1]:


        return False


return True

function to check given array a rainbow array

def is_rainbow(n):

for i in range(len(n)):


    if n[i]==n[len(n)-i-1] and str(n[i]) in q and is_increasing(n):


        continue


    else:


        return False


return True

x=int(input())

for i in range(x):

s1=int(input())


s=list(map(int,input().split()))


if (is_rainbow(s)):


    k.append(1)


else:


    k.append(0)

for l in k:

if l==1:


    print("yes")


else:


    print("no")

can you please tell me whats wrong in my code.

asked 09 Sep '17, 14:22

hemaabhijit007's gravatar image

2★hemaabhijit007
11
accept rate: 0%


Where are you calling the "is increasing" function? Also, what if your array is like

1 2 3 4 5 6 7 8 7 6 5 4 3 2 1

Above is not a rainbow array as it has an element more than 7, i.e. 8.

link

answered 09 Sep '17, 14:58

vijju123's gravatar image

4★vijju123 ♦♦
15.2k11859
accept rate: 18%

Yep, @vijju123 is right.

link

answered 09 Sep '17, 19:23

bhagatdivesh21's gravatar image

3★bhagatdivesh21
112
accept rate: 0%

Here is my solution in python !
what i essentially did was checked for palindrome and increment the checking factor by one starting with zero and also note the middle element has to be 7 and rest all cases are false

link

answered 09 Sep '17, 23:35

phantomhive's gravatar image

4★phantomhive
944
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×846
×262
×41

question asked: 09 Sep '17, 14:22

question was seen: 429 times

last updated: 09 Sep '17, 23:35