Daily Leetcode Challenge | NOV 16 | HINDI | Find the Power of K-Size Subarrays I

  Рет қаралды 66

Let us code

Let us code

Күн бұрын

Пікірлер: 5
@darshankumar5546
@darshankumar5546 7 күн бұрын
java solution at: 23:56
@darshankumar5546
@darshankumar5546 7 күн бұрын
English Explanation : kzbin.info/www/bejne/g6DLgKGqqMmWZ5Y
@darshankumar5546
@darshankumar5546 7 күн бұрын
//TIME COMPLEXITY=O(n) //SPACE COMPLEXITY=O(1) class Solution { public int[] resultsArray(int[] nums, int k) { int n=nums.length; int dp_prev=0; int dp_curr=0; int[] ans=new int[n-k+1]; for(int i=0;i0 && nums[i]==(nums[i-1]+1)){ dp_curr=dp_prev+1; } else{ dp_curr=0; } if(i>=(k-1)){ if(dp_curr>=(k-1)){ ans[i-(k-1)]=nums[i]; } else{ ans[i-(k-1)]=-1; } } dp_prev=dp_curr; } return ans; } }
@darshankumar5546
@darshankumar5546 7 күн бұрын
# approach-1 #TIME COMPLEXITY=O(n) #SPACE COMPLEXITY=O(n) class Solution: def resultsArray(self, nums: List[int], k: int) -> List[int]: n=len(nums) dp=[0 for i in range(n)] for i in range(1,n): if(nums[i]==nums[i-1]+1): dp[i]=dp[i-1]+1 print(dp) ans=[] for i in range(k-1,n): if(dp[i]>=(k-1)): ans.append(nums[i]) else: ans.append(-1) return ans
@darshankumar5546
@darshankumar5546 7 күн бұрын
# approach -2 #TIME COMPLEXITY=O(n) #SPACE COMPLEXITY=O(1) class Solution: def resultsArray(self, nums: List[int], k: int) -> List[int]: n=len(nums) dp_prev=0 dp_curr=0 ans=[] for i in range(n): if(i>0 and nums[i]==nums[i-1]+1): #dp[i]=dp[i-1]+1 dp_curr=dp_prev+1 else: dp_curr=0 if(i>=(k-1)): if(dp_curr>=(k-1)): ans.append(nums[i]) else: ans.append(-1) dp_prev=dp_curr print('dp=',dp_curr,end=' ') return ans
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 3,5 МЛН
How Many Balloons To Make A Store Fly?
00:22
MrBeast
Рет қаралды 102 МЛН
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 834 М.
Daily Leetcode Challenge | NOV 18 | HINDI | Defuse the Bomb
14:49
🚨 Junior Developer Mistakes That Will COST You in 2025 🚨
15:21
What Do Software Engineers ACTUALLY Do?
9:30
Sajjaad Khader
Рет қаралды 114 М.
While Loops in Python | Python Tutorial - Day #18
14:10
CodeWithHarry
Рет қаралды 664 М.
Are You Ready for WINDOWS IN THE CLOUD?
15:14
Switched to Linux
Рет қаралды 10 М.
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 3,5 МЛН