Move Zeros To The end of Array❗❗ | Hello world Programming Logic Easy | Hindi Explained
Vložit
- čas přidán 27. 01. 2022
- This is the video under the series of DATA STRUCTURE & ALGORITHM. Now we are going to solve Move Zeroes under Array sections
Join My Telegram channel for more Updates: telegram.me/helloworldbyprince
complete DSA preparation: github.com/Prince-1501/Comple...
----------------------------------------------------------------------------------------
Move Zeroes: leetcode.com/problems/move-ze...
code of Move Zeroes: github.com/Prince-1501/Hello_...
----------------------------------------------------------------------------------------
*Follow me *
LinkedIn► / iamprince
Facebook► / helloworldofficials
Instagram► / helloworldbyprince
Twitter► / prince_king_
Telegram► telegram.me/helloworldbyprince
----------------------------------------------------------------------------------------
►Our Playlists on:-
► Tree: • Tree Data Structure & ...
► Hashing: • Hashing Data Structure...
► Graph: • Graph Data Structure &...
► Matrix: • Matrix (Multidimension...
► STL: • Standard Template Libr...
► Leetcode: • LeetCode Solutions And...
►Competitive Programming: • Full course in Competi...
►C++ Full Course : • C++ full Course in HINDI
►Algorithms: • L-01 || Prefix Sum Arr...
►Data Structure: • Data Structures with C...
------------------------------------------------------------------------
🌟 Please leave a LIKE ❤️ and SUBSCRIBE for more AMAZING content! 🌟
✨ Tags ✨
Move Zeroes
Array playlist Hello world
Depth First Search
Array hello world
Types of graphs in Data structure & algorithms
Move Zeros To The end of Array
playlist Graph Hindi
hashing playlist Hello World
question asked in Google
off-campus placement
how to learn to code for beginners
Practice Tree data structure
Flood Fill Algorithms
The graph in a data structure in Hindi
Graph Full playlist for Beginners
algorithms
graph
dynamic programming
data structure
sorting algorithms
algorithm analysis
algorithm examples
gate computer science preparation
programming languages
#Array #Leetcode #programming
Thanks for motivation. Initially I directly jumped into solution but you motivated to solve it and I did. My solution was not much optimized. Now watching video for proper clearance.
You are doing really great just keep doing the work
hogya bhaiya yeh wala, took extra array for that, would love to learn new and more efficient approaches.
first, I thought let's check the solution instead of thinking about the solution but after listening to you, tried without lookin into solution and then boom got my solution🤯
public void moveZeroes(int[] nums) {
int j=0;
for(int i=0; i
suppose if array is [1,0,0,3] here intially j is 0th position of array
now keep on moving i until we reach non zero value ie - 3 now swap jth position with 3 and increase value of j here ur method fails ?
Best approach according to me :-
1) Count the number of 0s in the vector using *count(nums.begin(), nums.end(), target)* , here target = *0*
2) Remove all the 0s, *nums.erase(remove(nums.begin(), nums.end(), target), nums.end())* , target = *0*
3) Append all the 0s at the end using a for loop, *nums.push_back(0)*
After submission it said, faster than 74.53% of C++ online submissions...
Hope it helps !!! 😊😊😊
great work 👍
I tried the same method in a platform. It gave time limit exceeded
bhaiya bona approach ka TC same hee hai na
why haven't you declared " int j " in 2nd for loop ??
void moveZeroes(vector& nums) {
int c=0;
for(int i=0;i
Same bro... i did the same...
Yes 2nd approach kri maine but code nhi ho paya .. thank u ❤️
Amazing 😀
I solved it before watching ur solution
Bhaiya 2nd approach s kiya th code per wo fs gyi test cases mai
Where is the basics of these coding and what is the name of the app
class Solution:
def moveZeroes(self, nums: List[int]) -> None:
n=len(nums)
l, h=0,0
while(h
In last approach there is no need to add zeros at last if we swap i and j in the loop
Yeah u can do that as well i guess
Swapping increases time complexity, I did it and got TLE
Thanks brother nice explanation
Welcome
bhaiaya , you can take cf medium level questions or DP or online assesment ke questions !!
sure
Can anyone please tell the time complexity of 3rd approach? In which we are taking two pointers and checking if arr[i] is not equal to zero, then inserting it into arr[j]
O(n) only
@@Coder_DhruvArorait’s O(2N) but yeah if you consider drop constant way then yes it’s O(N)
var moveZeroes = function(nums) {
let j=0
for(let i=0; i< nums.length; i++){
if(nums[i] == 0){
[nums[i], nums[j]] = [nums[j], nums[i]];
j++;
}
}
return nums
}; complex approach in js
I was incrementing the j after the if statement. That's why no changes were being happen in the array. 😑😑
mne kiya tha 2nd approach se
its like O(n^2)
bhaiya swap wela approach and last wela same time complexity hai hee too hoo reha hai na
i also did from the same approach 😁
nice yar
Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
This is the best solution
Thanks a ton
I thought Second Approach and solved it.
merese hua tha lekin n2 complexity se
Sir jo questions companies me aate hai geeksforgeeks me questions karwa digieye
Sure dude
Ho gya solve but Space complexity is O(n)
swapping method is faster in both time and space complexity.
Hmm
Nice explanation but I think my solution is more efficient.
def pushZerosAtEnd(arr):
n = len(arr)
zero_index = 0
for i in range(n):
if arr[i] == 0:
if i > zero_index:
continue
else:
zero_index = i
else:
if zero_index < i:
arr[zero_index], arr[i] = arr[i], arr[zero_index]
zero_index += 1
return arr
oo great
Hi, I am from Pakistan........I am new to this leetcode ,I have only theoretical knowledge I have never implement such type of question ...what I do??? I am seeing your videos from the last three days .... I understand the question but can't think about approaches and more sad part is that also can't Implement code ....kindly suggest me how to be good at it ... Because I want to be good in it in 3 months......
Okay trust me and just start from my Playlist one by one
1. Hashing
2. Linked List
3. Stack and Queue
4. Heap
5. Tree
6. Graph
Do whatever I said in the video and follow every instruction strictly.
Each of my videos is based on one Question just try and learn from my videos and after completion of each Data structure just ping me over LinkedIn or CZcams comment section
and jo v videos dekhte ho, put comments on that video so that I can also track your progress
@@HelloWorldbyprince sure...!... Can I ask how you learned because you have such a clear concepts and approaches?
Bhaiya 5 bar attempted kiya or her baar naya constraint lagana pada phir bhi nahi hua
kya probelm aa rha hai aap batao ? mere code se kya alag hai ?
let temp = 0;
for(let i=0; i
koi issue nahi
its nice
@@HelloWorldbyprince Thank you very much sir
Complexity is O(n^2), could be optimized
second approch hum soche the
nice yaar good job
ho gaya
Nice
first approah ki code hai kisi ke pass
I though 2nd approch
waoo yaar good
5:27 solve ke naam pr mene decreasing order me sort krne ka socha 😢😢😢😢
yup, dhere dhere concept aur strong ho jayega relax
Nahi bana merse
koi na bro dhere dhere ban jayega
Sort kardo and reverse it
KHUDA KA KASTA KYON BOLA JAI SHRI RAM BOLO KATALU