We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
t=raw_input()t=int(t)foriinrange(0,t):m=raw_input()m=int(m)n=raw_input()n=int(n)li=raw_input()#list of elements from inputli=[int(i)foriinli.split(' ')]foriinrange(0,len(li)):if(m-li[i])inli[i+1:len(li)]:#check if the difference of m and element in the list exist, if yes then pick the index of those two elements.li1=li[i+1:len(li)]#if the same element appears twice, for example m=4 and the list has 2 2 4 1, this line helps in picking the next '2' at the position 1(starting from 0)x=li1.index(m-li[i])#position of the next element which forms the sum equal to m.printi+1,i+x+2#Since index starts from 0 add 1 to i, to print the second index, remember we have copied all the elements after position i, so i+x, since the index starts from 0, i+x+1, we left the element at position i while copying to li1, hence i+x+2break
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
Simple solution in python:
no need to sort