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.
### LIBRARIES ###fromcollectionsimportdefaultdict### INPUTS ###Trips=int(input())### FUNCTIONS ###defIceCream(index,dollar,data):foriindata:#If the values are heterogeneous, then we return the sorted indexes.if(dollar-i)indataand(i!=dollar-i):returnsorted([data[i][0],data[dollar-i][0]])#If the values are homogeneous, we make sure there is more than one instance.elif(dollar-i)indataand(i==dollar-i):iflen(data[i])>1:returnsorted([data[i][0],data[i][1]])else:continueelse:continue### OUTPUTS ### for_inrange(Trips):dollar=int(input())index=int(input())inputData=[int(i)foriininput().split()]#Initializing list objects, where the offset indexes will live.data=defaultdict(list)#enumerate returns the index and the value, here as i,j; respectively.fori,jinenumerate(inputData):data[j].append(i+1)#* unpacks the arguments.print(*IceCream(index,dollar,data))
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 →
Here is my Python3 solution that uses HashMap