Skip to content

Instantly share code, notes, and snippets.

View DarshanGowda0's full-sized avatar
🎯
Future Billionaire

Darshan N DarshanGowda0

🎯
Future Billionaire
  • NYC
View GitHub Profile
# naive solution with include/ignore decision technique
def numberOfPairs(nums, target):
def recur(nums, idx, remainingSum):
# we found a subArray which exhausted the target, so that's 1 way
if remainingSum == 0:
return 1
# when idx reaches end of the array and the remainingSum is non-zero
if idx == len(nums):
from collections import defaultdict
from random import randint
def numberOfPairs(nums, target):
mDict = defaultdict(int)
for num in nums:
if num < target:
mDict[num] += 1
print(mDict)
from math import ceil as h,floor as k;r=range;I=int;O=print;M=map;l=abs
for x in r(I(input())):
a,b=M(I,input().split());A=[];[A.append(list(M(I,input().split())))for i in r(a)];m,n=(a-1,b-1);C=set();D=C.add;L=-1;P=[];F=P.append;X=[]
if((m,n)==(1,1)or(m,n)==(0,0)):O(0);continue
d,e,f,g=(I(h(m/2)),I(k(m/2)),I(h(n/2)),I(k(n/2)));D((d,f));D((d,g));D((e,f));D((e,g))if(m%2!=0 or n%2!=0)else D((I(m/2),I(n/2)))
for i in r(a):
for j in r(b):
if(A[i][j]>L):L=A[i][j];P.clear();F((i,j))
elif(A[i][j]==L):F((i,j))
for p in P:[X.append(l(p[0]-c[0])+l(p[1]-c[1]))for c in C]