Daily Leetcode Challenge | JAN 14 | Java + Python | Find the Prefix Common Array of Two Arrays

  Рет қаралды 65

Let us code

Let us code

Күн бұрын

Пікірлер
@darshankumar5546
@darshankumar5546 13 күн бұрын
//java-MOST OPTIMAL // tc=O(n) // sc=O(n) class Solution { public int[] findThePrefixCommonArray(int[] A, int[] B) { int n=A.length; int commonEleCount=0; int[] ans=new int[n]; Set sett=new HashSet(n); for(int i=0;i
@darshankumar5546
@darshankumar5546 13 күн бұрын
Python documentaion for set: docs.python.org/2/library/sets.html
@ollieorion369
@ollieorion369 13 күн бұрын
Great Video 😌 Sir
@darshankumar5546
@darshankumar5546 12 күн бұрын
Thanks 🙂
@darshankumar5546
@darshankumar5546 13 күн бұрын
#python3-MOST OPTIMAL # tc=O(n) # sc=O(n) class Solution: def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]: ans=[] commonEleCount=0 n=len(A) sett=set() for i in range(n): if(A[i] in sett): commonEleCount+=1 else: sett.add(A[i]) if(B[i] in sett): commonEleCount+=1 else: sett.add(B[i]) ans.append(commonEleCount) return ans #i=0 commonEleCount=4 ans=[0,2,3,4] #set={1,3,2,4}
@darshankumar5546
@darshankumar5546 13 күн бұрын
# python - not optimal class Solution: def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]: ans=[] n=len(A) setA=set() setB=set() for i in range(n): setA.add(A[i]) setB.add(B[i]) if(A[i]==B[i] and i>0): ans.append(ans[-1]+1) else: ans.append(len(setA&setB)) return ans
Every team from the Bracket Buster! Who ya got? 😏
0:53
FailArmy Shorts
Рет қаралды 13 МЛН
$1 vs $500,000 Plane Ticket!
12:20
MrBeast
Рет қаралды 122 МЛН
BRAIN ROT | Why You Are Losing Control Of Your Brain?
17:40
Aevy TV
Рет қаралды 1,2 МЛН
one year of studying (it was a mistake)
12:51
Jeffrey Codes
Рет қаралды 264 М.