Remove Element - LeetCode #27 - Python, JavaScript, Java, C++

preview_player
Показать описание
Remove Element with Python, JavaScript, Java and C++, LeetCode #27!

Learn how to solve the Remove Element problem in this detailed video tutorial! The Remove Element problem is a common coding interview question where you need to remove all occurrences of a specified value from an integer array in-place. We'll walk through the problem statement, provide a step-by-step solution, and discuss the important considerations for ensuring your solution is efficient. By the end of this video, you'll have a clear understanding of how to modify the array and return the count of elements that are not equal to the given value. Perfect for those preparing for coding interviews or looking to improve their problem-solving skills, this Remove Element tutorial is a must-watch. Don't miss out on mastering the Remove Element problem!

CodingNinja offers other videos on programming, algorithms, and data structures as well. Subscribe to the channel so you don't miss out on new content!

------------------------------------------------------------------------------------------------------
⭐️ Please subscribe to my channel from here.

⭐️ Please upvote my post from here.
------------------------------------------------------------------------------------------------------

■ Timeline
0:04 Explain a basic idea
3:00 Coding
3:49 Time Complexity and Space Complexity

■ Blind 75 LeetCode questions

■ Twitter

■ Instagram

■ Problem Link

■ Codes in the video
- Python, JavaScript, Java and C++ are available from here.

■ Other Playlists

#leetcode #python #interview
Рекомендации по теме
Комментарии
Автор

how would this work if all numbers are target elements ?

PtYt
Автор

yep it's not working, you need to swap elements when you find the val if the read pointer is not at the last know "not val" index. I did a reverse read just because it's easier to put the values equal to val at the end.

You need to remove values equal to val in place and all non val elements should be at the end, hence the swap is needed, you are not doing this.

Also Time Complexity here is O(n), you loop through all elements of array n.

To get better ms run time you should manage edge cases first, array with no elements, array with only one elements as those can be done in O(1)

Daeku
Автор

This solution doesn't work at all, the point is to delete completely certain element from the array, but with this solution you will always have that one element which you want to delete in the array

JovanGrgur
welcome to shbcf.ru